include/linux/bitmap.h: make bitmap_fill() and bitmap_zero() consistent

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/334cfa48d38f5416c125a71a57f72d6cf634d797
Commit:     334cfa48d38f5416c125a71a57f72d6cf634d797
Parent:     fe81814c3e091adde489e9d7ac1179340845e396
Refname:    refs/heads/master
Author:     Andy Shevchenko <[email protected]>
AuthorDate: Tue Feb 6 15:38:20 2018 -0800
Committer:  Linus Torvalds <[email protected]>
CommitDate: Tue Feb 6 18:32:44 2018 -0800

    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/[email protected]
    Signed-off-by: Andy Shevchenko <[email protected]>
    Suggested-by: Rasmus Villemoes <[email protected]>
    Cc: Randy Dunlap <[email protected]>
    Cc: Yury Norov <[email protected]>
    Signed-off-by: Andrew Morton <[email protected]>
    Signed-off-by: Linus Torvalds <[email protected]>
---
 include/linux/bitmap.h | 15 ++++++++++-----
 1 file 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 @@
  *  bitmap_from_arr32(dst, buf, nbits)          Copy nbits from u32[] buf to dst
  *  bitmap_to_arr32(buf, src, nbits)            Copy nbits from buf to u32[] dst
  *
+ * Note, bitmap_zero() and bitmap_fill() operate over the region of
+ * unsigned longs, that is, bits behind bitmap till the unsigned long
+ * boundary will be zeroed or filled as well. Consider to use
+ * bitmap_clear() or bitmap_set() to make explicit zeroing or filling
+ * respectively.
  */
 
 /**
@@ -202,12 +207,12 @@ static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
 
 static inline void bitmap_fill(unsigned long *dst, unsigned int nbits)
 {
-	unsigned int nlongs = BITS_TO_LONGS(nbits);
-	if (!small_const_nbits(nbits)) {
-		unsigned int len = (nlongs - 1) * sizeof(unsigned long);
-		memset(dst, 0xff,  len);
+	if (small_const_nbits(nbits))
+		*dst = ~0UL;
+	else {
+		unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+		memset(dst, 0xff, len);
 	}
-	dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits);
 }
 
 static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.