Skip to content

Commit

Permalink
mm/vmstat: fix divide error at __fragmentation_index
Browse files Browse the repository at this point in the history
When order is -1 or too big, *1UL << order* will be 0, which will cause
a divide error.  Although it seems that all callers of
__fragmentation_index() will only do so with a valid order, the patch
can make it more robust.

Should prevent reoccurrences of
https://bugzilla.kernel.org/show_bug.cgi?id=196555

Link: http://lkml.kernel.org/r/1501751520-2598-1-git-send-email-wen.yang99@zte.com.cn
Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Reviewed-by: Jiang Biao <jiang.biao2@zte.com.cn>
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Wen Yang authored and Linus Torvalds committed Sep 7, 2017
1 parent 79b63f1 commit 88d6ac4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mm/vmstat.c
Original file line number Diff line number Diff line change
@@ -870,6 +870,9 @@ static int __fragmentation_index(unsigned int order, struct contig_page_info *in
{
unsigned long requested = 1UL << order;

if (WARN_ON_ONCE(order >= MAX_ORDER))
return 0;

if (!info->free_blocks_total)
return 0;

0 comments on commit 88d6ac4

Please sign in to comment.