Skip to contentSkip to conversation

lib/bitmap: Convert infinite while loop to for one

PATCH In review Andy Shevchenko 2 participants 2 messages Jun 9, 2020

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

PATCH 1/1 lib/bitmap: Convert infinite while loop to for one

Convert infinite while loop to for one in order to be more explicit in one place what we are doing with chunks.

---

Andrew, this can be folded to the fix

 lib/bitmap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/bitmap.c +2 -3
index 10f8fa0497e3..03ef42fbe658 100644
@@ -740,10 +740,10 @@ int bitmap_parse(const char *start, unsigned int buflen,
 	const char *end = strnchrnul(start, buflen, '\n') - 1;
 	int chunks = BITS_TO_U32(nmaskbits);
 	u32 *bitmap = (u32 *)maskp;
-	int chunk = 0;
 	int unset_bit;
+	int chunk;
 
-	while (1) {
+	for (chunk = 0; ; chunk++) {
 		end = bitmap_find_region_reverse(start, end);
 		if (start > end)
 			break;
@@ -758,7 +758,6 @@ int bitmap_parse(const char *start, unsigned int buflen,
 #endif
 		if (IS_ERR(end))
 			return PTR_ERR(end);
-		chunk++;
 	}
 
 	unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32;
Signature · 1 line
2.27.0.rc2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Andy Shevchenko

Convert infinite while loop to for one in order to be more explicit in one place what we are doing with chunks.

Quoted 37 lines

---

Andrew, this can be folded to the fix

 lib/bitmap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/bitmap.c +2 -3
index 10f8fa0497e3..03ef42fbe658 100644
@@ -740,10 +740,10 @@ int bitmap_parse(const char *start, unsigned int buflen,
 	const char *end = strnchrnul(start, buflen, '\n') - 1;
 	int chunks = BITS_TO_U32(nmaskbits);
 	u32 *bitmap = (u32 *)maskp;
-	int chunk = 0;
 	int unset_bit;
+	int chunk;
 
-	while (1) {
+	for (chunk = 0; ; chunk++) {
 		end = bitmap_find_region_reverse(start, end);
 		if (start > end)
 			break;
@@ -758,7 +758,6 @@ int bitmap_parse(const char *start, unsigned int buflen,
 #endif
 		if (IS_ERR(end))
 			return PTR_ERR(end);
-		chunk++;
 	}
 
 	unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32;
Signature · 1 line
2.27.0.rc2