[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <4a501c9f-245f-5ecd-46e9-dc0e71abf8a5@huaweicloud.com>
Date: Tue, 13 Jun 2023 17:45:28 +0800
From: "GONG, Ruiqi" <gongruiqi@...weicloud.com>
To: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: Linus Walleij <linus.walleij@...aro.org>,
linux-renesas-soc@...r.kernel.org, linux-gpio@...r.kernel.org,
linux-kernel@...r.kernel.org, gongruiqi1@...wei.com,
linux-sparse@...r.kernel.org,
Dan Carpenter <dan.carpenter@...aro.org>
Subject: Re: [PATCH] pinctrl: renesas: remove checker warnings: x | !y
Hi Geert,
On 2023/06/13 15:38, Geert Uytterhoeven wrote:
> Hi Gong,
>
> On Tue, Jun 13, 2023 at 4:13 AM GONG, Ruiqi <gongruiqi@...weicloud.com> wrote:
>> Eliminate the following Sparse reports when building with C=1:
>>
>> drivers/pinctrl/renesas/pinctrl-rzn1.c:187:52: warning: dubious: x | !y
>> drivers/pinctrl/renesas/pinctrl-rzn1.c:193:52: warning: dubious: x | !y
>>
>> Signed-off-by: GONG, Ruiqi <gongruiqi@...weicloud.com>
>
> Thanks for your patch!
>
> Looks like sparse needs to be taught the "|" is not used in a boolean
> context here?
Okay after reading the source code of Sparse I think what this kind of
warnings actually means is to hint us a possible misuse of "|" instead
of "||" (i.e. misusing a binary operator in a conditional context). Here
the code is doing binary operation (i.e. to flip a bit or two), so in
this sense the warnings should be just false alarms.
However, the original code is a bit weird for me because of the sudden
appearance of a boolean operator (i.e. "!") in the middle of a binary
calculation. And I think it looks better after this change, since it
makes the expression look more "binary". So maybe we can still consider
apply this change ;)
Greetings,
Ruiqi
>
>> --- a/drivers/pinctrl/renesas/pinctrl-rzn1.c
>> +++ b/drivers/pinctrl/renesas/pinctrl-rzn1.c
>> @@ -184,13 +184,15 @@ static void rzn1_hw_set_lock(struct rzn1_pinctrl *ipctl, u8 lock, u8 value)
>> * address | 1.
>> */
>> if (lock & LOCK_LEVEL1) {
>> - u32 val = ipctl->lev1_protect_phys | !(value & LOCK_LEVEL1);
>> + u32 val = ipctl->lev1_protect_phys |
>> + (value & LOCK_LEVEL1 ? 0 : 1);
>>
>> writel(val, &ipctl->lev1->status_protect);
>> }
>>
>> if (lock & LOCK_LEVEL2) {
>> - u32 val = ipctl->lev2_protect_phys | !(value & LOCK_LEVEL2);
>> + u32 val = ipctl->lev2_protect_phys |
>> + (value & LOCK_LEVEL2 ? 0 : 1);
>>
>> writel(val, &ipctl->lev2->status_protect);
>> }
>
> Gr{oetje,eeting}s,
>
> Geert
>
Powered by blists - more mailing lists