[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v11 1/7] bitmap: fix bitmap_count_one

From: Wei Wang
Subject: [Qemu-devel] [PATCH v11 1/7] bitmap: fix bitmap_count_one
Date: Tue, 11 Dec 2018 16:24:47 +0800

BITMAP_LAST_WORD_MASK(nbits) returns 0xffffffff when "nbits=0", which
makes bitmap_count_one fail to handle the "nbits=0" case. It appears to be
preferred to remain BITMAP_LAST_WORD_MASK identical to the kernel
implementation that it is ported from.

So this patch fixes bitmap_count_one to handle the nbits=0 case.

Inital Discussion Link:
Signed-off-by: Wei Wang <address@hidden>
CC: Juan Quintela <address@hidden>
CC: Dr. David Alan Gilbert <address@hidden>
CC: Peter Xu <address@hidden>
 include/qemu/bitmap.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 509eedd..679f1bd 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -221,6 +221,10 @@ static inline int bitmap_intersects(const unsigned long 
 static inline long bitmap_count_one(const unsigned long *bitmap, long nbits)
+    if (unlikely(!nbits)) {
+        return 0;
+    }
     if (small_nbits(nbits)) {
         return ctpopl(*bitmap & BITMAP_LAST_WORD_MASK(nbits));
     } else {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]