Skip to content

Commit

Permalink
dmapool: Validate parameters to dma_pool_create
Browse files Browse the repository at this point in the history
Check that 'align' is a power of two, like the API specifies.
Align 'size' to 'align' correctly -- the current code has an off-by-one.
The ALIGN macro in kernel.h doesn't.

Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Acked-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Matthew Wilcox committed Dec 4, 2007
1 parent 2cae367 commit 399154b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions mm/dmapool.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,18 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev,
{
struct dma_pool *retval;

if (align == 0)
if (align == 0) {
align = 1;
if (size == 0)
} else if (align & (align - 1)) {
return NULL;
else if (size < align)
size = align;
else if ((size % align) != 0) {
size += align + 1;
size &= ~(align - 1);
}

if (size == 0)
return NULL;

if ((size % align) != 0)
size = ALIGN(size, align);

if (allocation == 0) {
if (PAGE_SIZE < size)
allocation = size;
Expand Down

0 comments on commit 399154b

Please sign in to comment.