lkml.org 
[lkml]   [2015]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] mm: cma: fix CMA aligned offset calculation
Date
The CMA aligned offset calculation is incorrect for
non-zero order_per_bit values.

For example, if cma->order_per_bit=1, cma->base_pfn=
0x2f800000 and align_order=12, the function returns
a value of 0x17c00 instead of 0x400.

This patch fixes the CMA aligned offset calculation.

Cc: stable@vger.kernel.org
Signed-off-by: Danesh Petigara <dpetigara@broadcom.com>
Reviewed-by: Gregory Fong <gregory.0xf0@gmail.com>
---
mm/cma.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/cma.c b/mm/cma.c
index 75016fd..58f37bd 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -70,9 +70,13 @@ static unsigned long cma_bitmap_aligned_offset(struct cma *cma, int align_order)

if (align_order <= cma->order_per_bit)
return 0;
- alignment = 1UL << (align_order - cma->order_per_bit);
- return ALIGN(cma->base_pfn, alignment) -
- (cma->base_pfn >> cma->order_per_bit);
+
+ /*
+ * Find a PFN aligned to the specified order and return
+ * an offset represented in order_per_bits.
+ */
+ return (ALIGN(cma->base_pfn, (1UL << align_order))
+ - cma->base_pfn) >> cma->order_per_bit;
}

static unsigned long cma_bitmap_maxno(struct cma *cma)
--
1.9.1


\
 
 \ /
  Last update: 2015-02-24 21:01    [W:0.053 / U:0.396 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site