Skip to contentSkip to conversation

mm/vmstat: fix divide error at __fragmentation_index

PATCH In review [email protected] 1 participant 1 message Sep 6, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 99/119 mm/vmstat: fix divide error at __fragmentation_index

From: Wen Yang <[email protected]>
Subject: mm/vmstat: fix divide error at __fragmentation_index

When order is -1 or too big, *1UL << order* will be 0, which will cause 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

---

 mm/vmstat.c |    3 +++
 1 file changed, 3 insertions(+)
mm/vmstat.c renamed from mm/vmstat.c~mm-vmstat-fix-divide-error-at-__fragmentation_index +3 -0
diff -puN mm/vmstat.c~mm-vmstat-fix-divide-error-at-__fragmentation_index mm/vmstat.c
@@ -870,6 +870,9 @@ static int __fragmentation_index(unsigne
 {
 	unsigned long requested = 1UL << order;
 
+	if (WARN_ON_ONCE(order >= MAX_ORDER))
+		return 0;
+
 	if (!info->free_blocks_total)
 		return 0;
 

_