Skip to contentSkip to conversation

mm: change free_cma and free_pages declarations to unsigned

PATCH NAK Alexandru Moise 2 participants 3 messages Sep 27, 2015 – Sep 29, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mm: change free_cma and free_pages declarations to unsigned

Their stored values come from zone_page_state() which returns an unsigned long. To improve code correctness we should avoid mixing signed and unsigned integers.

---
 mm/page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/page_alloc.c +2 -2
index 48aaf7b..f55e3a2 100644
@@ -2242,7 +2242,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,
 	/* free_pages may go negative - that's OK */
 	long min = mark;
 	int o;
-	long free_cma = 0;
+	unsigned long free_cma = 0;
 
 	free_pages -= (1 << order) - 1;
 	if (alloc_flags & ALLOC_HIGH)
@@ -2280,7 +2280,7 @@ bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
 bool zone_watermark_ok_safe(struct zone *z, unsigned int order,
 			unsigned long mark, int classzone_idx, int alloc_flags)
 {
-	long free_pages = zone_page_state(z, NR_FREE_PAGES);
+	unsigned long free_pages = zone_page_state(z, NR_FREE_PAGES);
 
 	if (z->percpu_drift_mark && free_pages < z->percpu_drift_mark)
 		free_pages = zone_page_state_snapshot(z, NR_FREE_PAGES);
Signature · 7 lines
2.5.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 14 lines · Alexandru Moise

Their stored values come from zone_page_state() which returns an unsigned long. To improve code correctness we should avoid mixing signed and unsigned integers.

---
 mm/page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/page_alloc.c +0 -0
index 48aaf7b..f55e3a2 100644

mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2246

Quoted 6 lines
mm/page_alloc.c +1 -1
@@ -2242,7 +2242,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,
 	/* free_pages may go negative - that's OK */
 	long min = mark;
 	int o;
-	long free_cma = 0;
+	unsigned long free_cma = 0;
 

NAK.

free_cma is used with free_pages which is explicitly commented as saying it can go negative. With your patch, there is a signed/unsigned operation where the unsigned type cannot fit into the signed type which casts them both to unsigned which is then broken for the comparison. This patch looks broken for very subtle reasons. Please do not do any similar style patches to this because they can introduce subtle breakage if issues are not caught at review.

Signature · 8 lines
Mel Gorman
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 24 lines · Mel Gorman
Quoted 14 lines · Alexandru Moise

Their stored values come from zone_page_state() which returns an unsigned long. To improve code correctness we should avoid mixing signed and unsigned integers.

---
 mm/page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/page_alloc.c +0 -0
index 48aaf7b..f55e3a2 100644

mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2246

Quoted 6 lines
mm/page_alloc.c +1 -1
@@ -2242,7 +2242,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,
 	/* free_pages may go negative - that's OK */
 	long min = mark;
 	int o;
-	long free_cma = 0;
+	unsigned long free_cma = 0;
 

NAK.

Quoted 8 lines

free_cma is used with free_pages which is explicitly commented as saying it can go negative. With your patch, there is a signed/unsigned operation where the unsigned type cannot fit into the signed type which casts them both to unsigned which is then broken for the comparison. This patch looks broken for very subtle reasons. Please do not do any similar style patches to this because they can introduce subtle breakage if issues are not caught at review.

Understood, I thought the comment only applied to the "min" variable.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>