lkml.org 
[lkml]   [2007]   [Apr]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] dma_declare_coherent_memory wrong allocation
From
Date
On Mon, 2007-04-23 at 00:45 +0200, Guennadi Liakhovetski wrote:
> Right, thinko. How about using his:
>
> + int pages = DIV_ROUND_UP(size, PAGE_SIZE);

Actually, no ... this has to be size >> PAGE_SHIFT. The reason being
that the allocator is designed to allocate pages out of a device memory
buffer. If the size isn't a multiple of page size, we have to round
down (we can't allocate the last page if the memory we have is only part
of a page).

I suppose if you want to catch the unlikely nutcase where size <
PAGE_SIZE you could

if (unlikely(pages == 0))
goto out;
> + int bitmap_size = BITS_TO_LONGS(pages) * BYTES_PER_LONG;

This is fine, except the BYTES_PER_LONG. Traditionally, we do this with
sizeof(long). The only reason to have a #define for it is if it has to
be used in a macro (the compiler does sizeof() not the preprocessor).

How about just a simple

int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);

?

Then you don't need the first patch defining BYTES_PER_LONG.

> to also allow for size not an integer number of pages as Andrew noticed?
> This could be done in 2 patches:

James


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-04-23 18:53    [from the cache]
©2003-2011 Jasper Spaans. Advertise on this site