[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
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:


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2007-04-23 18:53    [W:0.049 / U:6.652 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site