All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] bitmap: fix BITMAP_LAST_WORD_MASK
@ 2018-07-31 10:01 Wei Wang
  2018-07-31 14:44 ` Juan Quintela
  2018-08-07  7:39 ` Peter Xu
  0 siblings, 2 replies; 9+ messages in thread
From: Wei Wang @ 2018-07-31 10:01 UTC (permalink / raw)
  To: qemu-devel, peterx, dgilbert, quintela; +Cc: mst

When "nbits = 0", which means no bits to mask, this macro is expected to
return 0, instead of 0xffffffff. This patch changes the macro to return
0 when there is no bit needs to be masked.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
CC: Juan Quintela <quintela@redhat.com>
CC: Dr. David Alan Gilbert <dgilbert@redhat.com>
CC: Peter Xu <peterx@redhat.com>
---
 include/qemu/bitmap.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

v1->v2 ChangeLog:
- fix the macro directly, instead of fixing the callers one by one.

diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 509eedd..9372423 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -60,7 +60,10 @@
  */
 
 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
-#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
+#define BITMAP_LAST_WORD_MASK(nbits)                       \
+(                                                          \
+    nbits ? (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) : 0 \
+)
 
 #define DECLARE_BITMAP(name,bits)                  \
         unsigned long name[BITS_TO_LONGS(bits)]
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-08-08  8:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-31 10:01 [Qemu-devel] [PATCH v2] bitmap: fix BITMAP_LAST_WORD_MASK Wei Wang
2018-07-31 14:44 ` Juan Quintela
2018-08-07  7:39 ` Peter Xu
2018-08-07  8:21   ` Wei Wang
2018-08-07  9:53     ` Dr. David Alan Gilbert
2018-08-08  1:34       ` Wei Wang
2018-08-08  8:29         ` Dr. David Alan Gilbert
2018-08-07 12:17     ` Peter Xu
2018-08-08  1:30       ` Wei Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.