From: zijun_hu Date: Sat, 10 Sep 2016 10:34:02 +0000 (+1000) Subject: mm/vmalloc.c: fix align value calculation error X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=93398a60761799103d968cf0b0f367e1eb8af6b7;p=deliverable%2Flinux.git mm/vmalloc.c: fix align value calculation error It causes double align requirement for __get_vm_area_node() if parameter size is power of 2 and VM_IOREMAP is set in parameter flags, for example size=0x10000 -> fls_long(0x10000)=17 -> align=0x20000 get_count_order_long() is implemented and used instead of fls_long() for fixing the bug, for example size=0x10000 -> get_count_order_long(0x10000)=16 -> align=0x10000 Link: http://lkml.kernel.org/r/fc045ecf-20fa-0722-b3ac-9a6140488fad@zoho.com Signed-off-by: zijun_hu Cc: Tejun Heo Cc: Johannes Weiner Cc: Minchan Kim Cc: David Rientjes Signed-off-by: Andrew Morton --- diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 299e76b59fe9..c18448de2c57 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -191,6 +191,23 @@ static inline unsigned fls_long(unsigned long l) return fls64(l); } +/** + * get_order_long - get order after rounding @l up to power of 2 + * @l: parameter + * + * it is same as get_count_order() but long type parameter + * or 0 is returned if @l == 0UL + */ +static inline int get_order_long(unsigned long l) +{ + if (l == 0UL) + return 0; + else if (l & (l - 1UL)) + return fls_long(l); + else + return fls_long(l) - 1; +} + /** * __ffs64 - find first set bit in a 64 bit word * @word: The 64 bit word diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 91f44e78c516..7d717f3eb288 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1360,7 +1360,7 @@ static struct vm_struct *__get_vm_area_node(unsigned long size, BUG_ON(in_interrupt()); if (flags & VM_IOREMAP) - align = 1ul << clamp_t(int, fls_long(size), + align = 1ul << clamp_t(int, get_order_long(size), PAGE_SHIFT, IOREMAP_MAX_ORDER); size = PAGE_ALIGN(size);