Commit 399154be2dcb6a58dbde9682162c38113cf3e40b

Authored by Matthew Wilcox
1 parent 2cae367e48

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>

Showing 1 changed file with 8 additions and 7 deletions Side-by-side Diff

... ... @@ -106,16 +106,17 @@
106 106 {
107 107 struct dma_pool *retval;
108 108  
109   - if (align == 0)
  109 + if (align == 0) {
110 110 align = 1;
111   - if (size == 0)
  111 + } else if (align & (align - 1)) {
112 112 return NULL;
113   - else if (size < align)
114   - size = align;
115   - else if ((size % align) != 0) {
116   - size += align + 1;
117   - size &= ~(align - 1);
118 113 }
  114 +
  115 + if (size == 0)
  116 + return NULL;
  117 +
  118 + if ((size % align) != 0)
  119 + size = ALIGN(size, align);
119 120  
120 121 if (allocation == 0) {
121 122 if (PAGE_SIZE < size)