qemu-devel
[Top][All Lists]
Advanced

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

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


From: Dr. David Alan Gilbert
Subject: Re: [Qemu-devel] [PATCH v11 1/7] bitmap: fix bitmap_count_one
Date: Thu, 13 Dec 2018 14:28:01 +0000
User-agent: Mutt/1.10.1 (2018-07-13)

* Wei Wang (address@hidden) wrote:
> 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.

OK; it's a little odd that it's only bitmap_count_one that's being fixed
for this case; but OK.


Reviewed-by: Dr. David Alan Gilbert <address@hidden>

> 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
> 
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK



reply via email to

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