diff options
| author | Wei Wang <wei.w.wang@intel.com> | 2018-12-11 16:24:47 +0800 |
|---|---|---|
| committer | Dr. David Alan Gilbert <dgilbert@redhat.com> | 2019-03-06 10:49:17 +0000 |
| commit | e7c91368d24637f077b457187f8dff4767dfadae (patch) | |
| tree | 6698304bbe36e6d9fa5df94e7ce17a9dd05fe505 /include/qemu/bitmap.h | |
| parent | 609d3844076ebcfc507fb8a8ddaf2cb7d7c6bc48 (diff) | |
| download | focaccia-qemu-e7c91368d24637f077b457187f8dff4767dfadae.tar.gz focaccia-qemu-e7c91368d24637f077b457187f8dff4767dfadae.zip | |
bitmap: fix bitmap_count_one
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/qemu-devel@nongnu.org/msg554316.html 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> Message-Id: <1544516693-5395-2-git-send-email-wei.w.wang@intel.com> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'include/qemu/bitmap.h')
| -rw-r--r-- | include/qemu/bitmap.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 509eeddece..679f1bdce4 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 { |