mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-01 12:04:08 +00:00
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 can be used instead of fls_long() for fixing the bug, for example size=0x10000 -> get_count_order_long(0x10000)=16 -> align=0x10000 [akpm@linux-foundation.org: s/get_order_long()/get_count_order_long()/] [zijun_hu@zoho.com: fixes] Link: http://lkml.kernel.org/r/57AABC8B.1040409@zoho.com [akpm@linux-foundation.org: locate get_count_order_long() next to get_count_order()] [akpm@linux-foundation.org: move get_count_order[_long] definitions to pick up fls_long()] [zijun_hu@htc.com: move out get_count_order[_long]() from __KERNEL__ scope] Link: http://lkml.kernel.org/r/57B2C4CE.80303@zoho.com Link: http://lkml.kernel.org/r/fc045ecf-20fa-0722-b3ac-9a6140488fad@zoho.com Signed-off-by: zijun_hu <zijun_hu@htc.com> Cc: Tejun Heo <tj@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Minchan Kim <minchan@kernel.org> Cc: David Rientjes <rientjes@google.com> Signed-off-by: zijun_hu <zijun_hu@htc.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
7c5f64f844
commit
252e5c6e2e
2 changed files with 30 additions and 14 deletions
|
@ -65,16 +65,6 @@ static inline int get_bitmask_order(unsigned int count)
|
||||||
return order; /* We could be slightly more clever with -1 here... */
|
return order; /* We could be slightly more clever with -1 here... */
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int get_count_order(unsigned int count)
|
|
||||||
{
|
|
||||||
int order;
|
|
||||||
|
|
||||||
order = fls(count) - 1;
|
|
||||||
if (count & (count - 1))
|
|
||||||
order++;
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
|
|
||||||
static __always_inline unsigned long hweight_long(unsigned long w)
|
static __always_inline unsigned long hweight_long(unsigned long w)
|
||||||
{
|
{
|
||||||
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
|
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
|
||||||
|
@ -191,6 +181,32 @@ static inline unsigned fls_long(unsigned long l)
|
||||||
return fls64(l);
|
return fls64(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int get_count_order(unsigned int count)
|
||||||
|
{
|
||||||
|
int order;
|
||||||
|
|
||||||
|
order = fls(count) - 1;
|
||||||
|
if (count & (count - 1))
|
||||||
|
order++;
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_count_order_long - get order after rounding @l up to power of 2
|
||||||
|
* @l: parameter
|
||||||
|
*
|
||||||
|
* it is same as get_count_order() but with long type parameter
|
||||||
|
*/
|
||||||
|
static inline int get_count_order_long(unsigned long l)
|
||||||
|
{
|
||||||
|
if (l == 0UL)
|
||||||
|
return -1;
|
||||||
|
else if (l & (l - 1UL))
|
||||||
|
return (int)fls_long(l);
|
||||||
|
else
|
||||||
|
return (int)fls_long(l) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __ffs64 - find first set bit in a 64 bit word
|
* __ffs64 - find first set bit in a 64 bit word
|
||||||
* @word: The 64 bit word
|
* @word: The 64 bit word
|
||||||
|
|
|
@ -1359,14 +1359,14 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
|
||||||
struct vm_struct *area;
|
struct vm_struct *area;
|
||||||
|
|
||||||
BUG_ON(in_interrupt());
|
BUG_ON(in_interrupt());
|
||||||
if (flags & VM_IOREMAP)
|
|
||||||
align = 1ul << clamp_t(int, fls_long(size),
|
|
||||||
PAGE_SHIFT, IOREMAP_MAX_ORDER);
|
|
||||||
|
|
||||||
size = PAGE_ALIGN(size);
|
size = PAGE_ALIGN(size);
|
||||||
if (unlikely(!size))
|
if (unlikely(!size))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (flags & VM_IOREMAP)
|
||||||
|
align = 1ul << clamp_t(int, get_count_order_long(size),
|
||||||
|
PAGE_SHIFT, IOREMAP_MAX_ORDER);
|
||||||
|
|
||||||
area = kzalloc_node(sizeof(*area), gfp_mask & GFP_RECLAIM_MASK, node);
|
area = kzalloc_node(sizeof(*area), gfp_mask & GFP_RECLAIM_MASK, node);
|
||||||
if (unlikely(!area))
|
if (unlikely(!area))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Reference in a new issue