diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2018-02-06 18:38:20 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-06 21:32:44 -0500 |
commit | 334cfa48d38f5416c125a71a57f72d6cf634d797 (patch) | |
tree | fee2a87aa695e98d29fe0043b58525101a860c2f | |
parent | fe81814c3e091adde489e9d7ac1179340845e396 (diff) |
include/linux/bitmap.h: make bitmap_fill() and bitmap_zero() consistent
Behaviour of bitmap_fill() differs from bitmap_zero() in a way how bits
behind bitmap are handed. bitmap_zero() clears entire bitmap by unsigned
long boundary, while bitmap_fill() mimics bitmap_set().
Here we change bitmap_fill() behaviour to be consistent with bitmap_zero()
and add a note to documentation.
The change might reveal some bugs in the code where unused bits are
handled differently and in such cases bitmap_set() has to be used.
Link: http://lkml.kernel.org/r/20180109172430.87452-4-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Yury Norov <ynorov@caviumnetworks.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/bitmap.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index e43533ec7660..d9bf699e0e7a 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h | |||
@@ -67,6 +67,11 @@ | |||
67 | * bitmap_from_arr32(dst, buf, nbits) Copy nbits from u32[] buf to dst | 67 | * bitmap_from_arr32(dst, buf, nbits) Copy nbits from u32[] buf to dst |
68 | * bitmap_to_arr32(buf, src, nbits) Copy nbits from buf to u32[] dst | 68 | * bitmap_to_arr32(buf, src, nbits) Copy nbits from buf to u32[] dst |
69 | * | 69 | * |
70 | * Note, bitmap_zero() and bitmap_fill() operate over the region of | ||
71 | * unsigned longs, that is, bits behind bitmap till the unsigned long | ||
72 | * boundary will be zeroed or filled as well. Consider to use | ||
73 | * bitmap_clear() or bitmap_set() to make explicit zeroing or filling | ||
74 | * respectively. | ||
70 | */ | 75 | */ |
71 | 76 | ||
72 | /** | 77 | /** |
@@ -202,12 +207,12 @@ static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) | |||
202 | 207 | ||
203 | static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) | 208 | static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) |
204 | { | 209 | { |
205 | unsigned int nlongs = BITS_TO_LONGS(nbits); | 210 | if (small_const_nbits(nbits)) |
206 | if (!small_const_nbits(nbits)) { | 211 | *dst = ~0UL; |
207 | unsigned int len = (nlongs - 1) * sizeof(unsigned long); | 212 | else { |
208 | memset(dst, 0xff, len); | 213 | unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
214 | memset(dst, 0xff, len); | ||
209 | } | 215 | } |
210 | dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); | ||
211 | } | 216 | } |
212 | 217 | ||
213 | static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, | 218 | static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, |