Re: [PATCH 2/2] leds: ns2: Fix wrong boolean expression

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

 



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.

>
> 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.

>
>
>> @@ -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;




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux