[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v10 1/7] bitmap: fix bitmap_count_one
From: |
Wei Wang |
Subject: |
[Qemu-devel] [PATCH v10 1/7] bitmap: fix bitmap_count_one |
Date: |
Mon, 3 Dec 2018 10:18:25 +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:
https://www.mail-archive.com/address@hidden/msg554316.html
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
*src1,
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 {
--
1.8.3.1