Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/cma_debug: correct size input to bitmap function

In CMA, 1 bit in bitmap means 1 << order_per_bits pages so size of
bitmap is cma->count >> order_per_bits rather than just cma->count.
This patch fixes it.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Stefan Strogin <stefan.strogin@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Joonsoo Kim and committed by
Linus Torvalds
d56e84b4 2292c0b1

+4 -3
+4 -3
mm/cma_debug.c
··· 39 39 40 40 mutex_lock(&cma->lock); 41 41 /* pages counter is smaller than sizeof(int) */ 42 - used = bitmap_weight(cma->bitmap, (int)cma->count); 42 + used = bitmap_weight(cma->bitmap, (int)cma_bitmap_maxno(cma)); 43 43 mutex_unlock(&cma->lock); 44 44 *val = (u64)used << cma->order_per_bit; 45 45 ··· 52 52 struct cma *cma = data; 53 53 unsigned long maxchunk = 0; 54 54 unsigned long start, end = 0; 55 + unsigned long bitmap_maxno = cma_bitmap_maxno(cma); 55 56 56 57 mutex_lock(&cma->lock); 57 58 for (;;) { 58 - start = find_next_zero_bit(cma->bitmap, cma->count, end); 59 + start = find_next_zero_bit(cma->bitmap, bitmap_maxno, end); 59 60 if (start >= cma->count) 60 61 break; 61 - end = find_next_bit(cma->bitmap, cma->count, start); 62 + end = find_next_bit(cma->bitmap, bitmap_maxno, start); 62 63 maxchunk = max(end - start, maxchunk); 63 64 } 64 65 mutex_unlock(&cma->lock);