[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2] bitmap: fix BITMAP_LAST_WORD_MASK
From: |
Peter Xu |
Subject: |
Re: [Qemu-devel] [PATCH v2] bitmap: fix BITMAP_LAST_WORD_MASK |
Date: |
Tue, 7 Aug 2018 15:39:05 +0800 |
User-agent: |
Mutt/1.10.0 (2018-05-17) |
On Tue, Jul 31, 2018 at 06:01:18PM +0800, Wei Wang wrote:
> 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 <address@hidden>
> CC: Juan Quintela <address@hidden>
> CC: Dr. David Alan Gilbert <address@hidden>
> CC: Peter Xu <address@hidden>
Reviewed-by: Peter Xu <address@hidden>
Is there any existing path that can trigger this nbits==0?
> ---
> 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
>
Regards,
--
Peter Xu
- Re: [Qemu-devel] [PATCH v2] bitmap: fix BITMAP_LAST_WORD_MASK,
Peter Xu <=