Skip to contentSkip to conversation

linux/bitmap.h: comments on BITMAP_LAST_WORD_MASK

PATCH New Wei Wang 1 participant 1 message Jul 27, 2018 Bitmap API

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH v2 1/1 linux/bitmap.h: comments on BITMAP_LAST_WORD_MASK

When "nbits = 0" which means no bits to mask, this macro is expected to return 0, instead of 0xffffffff. Currently, the "nbits = 0" case is avoided by the callers themselves (e.g.__bitmap_intersects, __bitmap_weight). This corner case should be explicitly noted.

This patch simply adds a comment above the macro as a note to users about the corner case.

Cc Andy Shevchenko <[email protected]>
Cc Yury Norov <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Rasmus Villemoes <[email protected]>
---
 include/linux/bitmap.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/bitmap.h +1 -0
index 1ee46f4..4e64d1f 100644
@@ -194,6 +194,7 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf,
 				   const unsigned long *maskp, int nmaskbits);
 
 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
+/* "nbits = 0" is not applicable to this macro. Callers should avoid that. */
 #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
 
 #define small_const_nbits(nbits) \
Signature · 1 line
2.7.4