[Top][All Lists]

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

Re: [Qemu-devel] [PATCH 1/2] bitmap.h: add comments to BITMAP_LAST_WORD_

From: Wei Wang
Subject: Re: [Qemu-devel] [PATCH 1/2] bitmap.h: add comments to BITMAP_LAST_WORD_MASK
Date: Tue, 31 Jul 2018 17:06:38 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

On 07/30/2018 09:19 PM, Juan Quintela wrote:
Wei Wang <address@hidden> wrote:
On 07/30/2018 03:13 PM, Wei Wang wrote:
This macro was ported from Linux and we've reached an aggreement there
that the corner case "nbits = 0" is not applicable to this macro, because
when "nbits = 0", which means no bits to mask, this macro is expected to
return 0, instead of 0xffffffff. This patch simply adds a comment above
the macro as a note to users about the corner case.

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

diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 509eedd..f53c640 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -60,6 +60,7 @@
     #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) &
+/* "nbits = 0" is not applicable to this macro. Callers should avoid that. */
   #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 
     #define DECLARE_BITMAP(name,bits)                  \
A better fix would be to directly change the macro to:  nbits ? (~0UL
(-(nbits) & (BITS_PER_LONG - 1))) : 0,
so that we don't need to fix other callers like bitmap_full,

So just post this out for a discussion whether it's preferred to just
adding note comments as we did for linux or fixing the macro directly.

On one hand:
a - we have copied it form linux, we don't want to diverge
On the other hand:
b - it is much easier to use if we change the macro

So, it is a tought one.

I slightly preffer b), but will not object to a either.  As you are the
one doing the patch, your choice.

Thanks Juan. I plan to choose b - fixing the macro directly.


reply via email to

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