linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleh Kravchenko <oleg@kaa.org.ua>
To: Pavel Machek <pavel@ucw.cz>
Cc: linux-leds@vger.kernel.org
Subject: Re: [PATCH 2/2] leds: ns2: Fix wrong boolean expression
Date: Tue, 3 Sep 2019 22:46:32 +0300	[thread overview]
Message-ID: <4B55F03E-03C9-44BA-A4CB-AADA29FC4271@kaa.org.ua> (raw)
In-Reply-To: <20190903185006.GA10875@amd>

Pavel,

> On Sep 3, 2019, at 9:50 PM, Pavel Machek <pavel@ucw.cz> wrote:
> 
> On Tue 2019-09-03 19:00:21, Oleh Kravchenko wrote:
>> Hello Pavel,
>> 
>> 03.09.19 17:12, Pavel Machek пише:
>>> On Tue 2019-09-03 15:50:20, Oleh Kravchenko wrote:
>>>> Error was detected by PVS-Studio:
>>>> V792 The '__gpio_cansleep' function located to the right of
>>>> the operator '|' will be called regardless of the value of
>>>> the left operand. Perhaps, it is better to use '||'.
>>> 1st: original code is not wrong
>> 
>> '|' is bitwise operation, if it really means *OR* then should be '||' -
>> led_dat->can_sleep is bool.
> 
> I see that || would be more natural. But | also works.
> 
>>> 2nd: you are introducing a bug
>> 
>> No, because if GPIOs *slow* can sleep and GPIO *cmd* can't sleep
>> it will call gpio_set_value_cansleep() for both.
> 
> If just one of them can sleep, can_sleep will be 0, and bad things
> will happen, right?

With current code if just one of them can sleep, can_sleep will be not zero (!= 0).
And bad things will happen.

> 
> 
>>>> @@ -205,7 +205,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
>>>> 	led_dat->cdev.groups = ns2_led_groups;
>>>> 	led_dat->cmd = template->cmd;
>>>> 	led_dat->slow = template->slow;
>>>> -	led_dat->can_sleep = gpio_cansleep(led_dat->cmd) |
>>>> +	led_dat->can_sleep = gpio_cansleep(led_dat->cmd) &&
>>>> 				gpio_cansleep(led_dat->slow);
>>>> 	if (led_dat->can_sleep)
>>>> 		led_dat->cdev.brightness_set_blocking = ns2_led_set_blocking;
> 
> Best regards,
> 									Pavel
> -- 
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


  reply	other threads:[~2019-09-03 19:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03 12:50 [PATCH 1/2] leds: mlxreg: Fix possible buffer overflow Oleh Kravchenko
2019-09-03 12:50 ` [PATCH 2/2] leds: ns2: Fix wrong boolean expression Oleh Kravchenko
2019-09-03 14:12   ` Pavel Machek
2019-09-03 16:00     ` Oleh Kravchenko
2019-09-03 18:50       ` Pavel Machek
2019-09-03 19:46         ` Oleh Kravchenko [this message]
2019-09-03 21:02         ` Oleh Kravchenko
2019-09-03 14:12 ` [PATCH 1/2] leds: mlxreg: Fix possible buffer overflow Pavel Machek
2019-09-03 18:11   ` Oleh Kravchenko
2019-09-07 19:36     ` Pavel Machek
2019-09-08  8:57       ` Oleh Kravchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B55F03E-03C9-44BA-A4CB-AADA29FC4271@kaa.org.ua \
    --to=oleg@kaa.org.ua \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).