Skip to contentSkip to conversation

bitmap: Drop unnecessary 0 check for u32 array operations

PATCH In review Andy Shevchenko 3 participants 3 messages May 31, 2018 – Jun 14, 2018

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

PATCH 1/1 bitmap: Drop unnecessary 0 check for u32 array operations

The nbits == 0 is safe to be supplied to the function body, so, remove unnecessary checks in bitmap_to_arr32() and bitmap_from_arr32().

---
 lib/bitmap.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
lib/bitmap.c +1 -8
index 58f9750e49c6..33e95cd359a2 100644
@@ -1132,14 +1132,10 @@ EXPORT_SYMBOL(bitmap_copy_le);
  *	@buf: array of u32 (in host byte order), the source bitmap
  *	@nbits: number of bits in @bitmap
  */
-void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf,
-						unsigned int nbits)
+void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf, unsigned int nbits)
 {
 	unsigned int i, halfwords;
 
-	if (!nbits)
-		return;
-
 	halfwords = DIV_ROUND_UP(nbits, 32);
 	for (i = 0; i < halfwords; i++) {
 		bitmap[i/2] = (unsigned long) buf[i];
@@ -1163,9 +1159,6 @@ void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits)
 {
 	unsigned int i, halfwords;
 
-	if (!nbits)
-		return;
-
 	halfwords = DIV_ROUND_UP(nbits, 32);
 	for (i = 0; i < halfwords; i++) {
 		buf[i] = (u32) (bitmap[i/2] & UINT_MAX);
Signature · 1 line
2.17.0
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Andy Shevchenko

The nbits == 0 is safe to be supplied to the function body, so, remove unnecessary checks in bitmap_to_arr32() and bitmap_from_arr32().

Indeed. Thanks for the catch.

Quoted 9 lines
---
 lib/bitmap.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
lib/bitmap.c +0 -0
index 58f9750e49c6..33e95cd359a2 100644

lib/bitmap.c EXPORT_SYMBOL(bitmap_copy_le); · line 1135

Quoted 6 lines
lib/bitmap.c +1 -2
@@ -1132,14 +1132,10 @@ EXPORT_SYMBOL(bitmap_copy_le);
  *	@buf: array of u32 (in host byte order), the source bitmap
  *	@nbits: number of bits in @bitmap
  */
-void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf,
-						unsigned int nbits)
+void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf, unsigned int nbits)

This line is 81 characters length, and it will trigger checkpatch warning. (But I'm OK with it.)

Quoted 21 lines
lib/bitmap.c +0 -6
 {
 	unsigned int i, halfwords;
 
-	if (!nbits)
-		return;
-
 	halfwords = DIV_ROUND_UP(nbits, 32);
 	for (i = 0; i < halfwords; i++) {
 		bitmap[i/2] = (unsigned long) buf[i];
@@ -1163,9 +1159,6 @@ void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits)
 {
 	unsigned int i, halfwords;
 
-	if (!nbits)
-		return;
-
 	halfwords = DIV_ROUND_UP(nbits, 32);
 	for (i = 0; i < halfwords; i++) {
 		buf[i] = (u32) (bitmap[i/2] & UINT_MAX);
Signature · 1 line
2.17.0
#2 lore raw
Quoted 8 lines · Yury Norov
Quoted 4 lines · Andy Shevchenko

The nbits == 0 is safe to be supplied to the function body, so, remove unnecessary checks in bitmap_to_arr32() and bitmap_from_arr32().

+void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf, unsigned int nbits)

This line is 81 characters length, and it will trigger checkpatch warning. (But I'm OK with it.)

I really don't care about ) at the end potentially not visible on the screen (who is using nice old hardware terminals? :-) ).

Quoted 1 line

Thanks.

Signature · 2 lines
With Best Regards,
Andy Shevchenko