qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo


From: Markus Armbruster
Subject: Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
Date: Mon, 27 Sep 2021 09:16:42 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

Bin Meng <bmeng.cn@gmail.com> writes:

> Hi Markus,
>
> On Mon, Sep 27, 2021 at 2:51 PM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Bin Meng <bmeng.cn@gmail.com> writes:
>>
>> > GCC seems to be strict about processing pattern like "!!for & bar".
>> > When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
>> >
>> >   suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ 
>> > to ‘~’ [-Werror=parentheses]
>> >
>> > Add a () around "foo && bar", which also improves code readability.
>> >
>> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>> > ---
>> >
>> >  hw/dma/sifive_pdma.c | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
>> > index b4fd40573a..b8ec7621f3 100644
>> > --- a/hw/dma/sifive_pdma.c
>> > +++ b/hw/dma/sifive_pdma.c
>> > @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr 
>> > offset,
>> >      offset &= 0xfff;
>> >      switch (offset) {
>> >      case DMA_CONTROL:
>> > -        claimed = !!s->chan[ch].control & CONTROL_CLAIM;
>> > +        claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
>> >
>> >          if (!claimed && (value & CONTROL_CLAIM)) {
>> >              /* reset Next* registers */
>>
>> Old code
>>
>>     first double-negate, mapping zero to zero, non-zero to one
>>     then mask, which does nothing, because CONTROL_CLAIM is 1
>>
>> New code:
>>
>>     first mask, yielding 0 or 1
>>     then double-negate, which does nothing
>>
>> Looks like a bug fix to me.  If I'm right, the commit message is wrong,
>> and the double negate is redundant.
>>
>
> Thanks for the review. The double negate is not needed with
> CONTROL_CLAIM which is 1, but is needed if the bit is in another
> position.

It's not needed even then: conversion from integer type to bool takes
care of it.  It's not wrong, though.

However, the commit message does look wrong to me.




reply via email to

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