mirror of
https://github.com/torvalds/linux.git
synced 2024-09-20 23:13:00 +00:00
dmapool: Validate parameters to dma_pool_create
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>
This commit is contained in:
parent
2cae367e48
commit
399154be2d
15
mm/dmapool.c
15
mm/dmapool.c
|
@ -106,16 +106,17 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev,
|
||||||
{
|
{
|
||||||
struct dma_pool *retval;
|
struct dma_pool *retval;
|
||||||
|
|
||||||
if (align == 0)
|
if (align == 0) {
|
||||||
align = 1;
|
align = 1;
|
||||||
|
} else if (align & (align - 1)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
else if (size < align)
|
|
||||||
size = align;
|
if ((size % align) != 0)
|
||||||
else if ((size % align) != 0) {
|
size = ALIGN(size, align);
|
||||||
size += align + 1;
|
|
||||||
size &= ~(align - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (allocation == 0) {
|
if (allocation == 0) {
|
||||||
if (PAGE_SIZE < size)
|
if (PAGE_SIZE < size)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user