From 18e44d3eaf6fe1c9473c31feee49bbc0cd89bc3f Mon Sep 17 00:00:00 2001 From: Jack Cheung Date: Mon, 28 Nov 2011 16:41:28 -0800 Subject: [PATCH] mm: Cast lowmem_reserve to long z->lowmem_reserve[classzone_idx] is an unsigned long but free_pages and min are longs. If free_pages is negative, the function will incorrectly return true because it will treat the negative long as a large, positive unsigned long. This change casts z->lowmem_reserve to a long and fixes a typo in the comment. Change-Id: Icada1fa5ca650fbcdb0656f637adbb98f223eec5 Signed-off-by: Jack Cheung (cherry picked from commit 9f41da81017657a194a4e145bab337f13a4d7fd9) --- mm/page_alloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 918330f71db..1e145ef92c3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1548,8 +1548,9 @@ static inline int should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) static bool __zone_watermark_ok(struct zone *z, int order, unsigned long mark, int classzone_idx, int alloc_flags, long free_pages) { - /* free_pages my go negative - that's OK */ + /* free_pages may go negative - that's OK */ long min = mark; + long lowmem_reserve = z->lowmem_reserve[classzone_idx]; int o; free_pages -= (1 << order) - 1; @@ -1558,7 +1559,7 @@ static bool __zone_watermark_ok(struct zone *z, int order, unsigned long mark, if (alloc_flags & ALLOC_HARDER) min -= min / 4; - if (free_pages <= min + z->lowmem_reserve[classzone_idx]) + if (free_pages <= min + lowmem_reserve) return false; for (o = 0; o < order; o++) { /* At the next order, this order's pages become unavailable */