Commit d2dc1f4a authored by Jan Beulich's avatar Jan Beulich Committed by Linus Torvalds

dma: fix order calculation in dma_mark_declared_memory_occupied()

get_order() takes byte-sized input, not a page-granular one.

Irrespective of this fix I'm inclined to believe that this doesn't work
right anyway - bitmap_allocate_region() has an implicit assumption of
'pos' being suitable for 'order', which this function doesn't seem to
enforce (and since it's being called with a byte-granular value there's no
reason to believe that the callers would make sure device_addr is passed
accordingly - it's also not documented that way).
Signed-off-by: default avatarJan Beulich <jbeulich@novell.com>
Cc: James E.J. Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Dmitry Baryshkov <dbaryshkov@gmail.com>
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 978cc90c
...@@ -77,15 +77,14 @@ void *dma_mark_declared_memory_occupied(struct device *dev, ...@@ -77,15 +77,14 @@ void *dma_mark_declared_memory_occupied(struct device *dev,
{ {
struct dma_coherent_mem *mem = dev->dma_mem; struct dma_coherent_mem *mem = dev->dma_mem;
int pos, err; int pos, err;
int pages = (size + (device_addr & ~PAGE_MASK) + PAGE_SIZE - 1);
pages >>= PAGE_SHIFT; size += device_addr & ~PAGE_MASK;
if (!mem) if (!mem)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
pos = (device_addr - mem->device_base) >> PAGE_SHIFT; pos = (device_addr - mem->device_base) >> PAGE_SHIFT;
err = bitmap_allocate_region(mem->bitmap, pos, get_order(pages)); err = bitmap_allocate_region(mem->bitmap, pos, get_order(size));
if (err != 0) if (err != 0)
return ERR_PTR(err); return ERR_PTR(err);
return mem->virt_base + (pos << PAGE_SHIFT); return mem->virt_base + (pos << PAGE_SHIFT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment