lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <38383f8a-a71d-22ff-93ab-8ac14f5aba07@roeck-us.net>
Date:   Mon, 27 Dec 2021 16:36:34 -0800
From:   Guenter Roeck <linux@...ck-us.net>
To:     Aleksandr Mezin <mezin.alexander@...il.com>
Cc:     Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>,
        Jean Delvare <jdelvare@...e.com>, linux-hwmon@...r.kernel.org,
        linux-kernel@...r.kernel.org, Abaci Robot <abaci@...ux.alibaba.com>
Subject: Re: [PATCH] hwmon: Use min() instead of doing it manually

On 12/27/21 4:18 PM, Aleksandr Mezin wrote:
> On Mon, Dec 27, 2021 at 9:43 PM Guenter Roeck <linux@...ck-us.net> wrote:
>>
>> On 12/27/21 3:36 AM, Jiapeng Chong wrote:
>>> Eliminate following coccicheck warning:
>>>
>>> ./drivers/hwmon/nzxt-smart2.c:461:12-13: WARNING opportunity for min().
>>>
>>> Reported-by: Abaci Robot <abaci@...ux.alibaba.com>
>>> Signed-off-by: Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>
>>> ---
>>>    drivers/hwmon/nzxt-smart2.c | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/hwmon/nzxt-smart2.c b/drivers/hwmon/nzxt-smart2.c
>>> index 534d39b8908e..b30de7441fbb 100644
>>> --- a/drivers/hwmon/nzxt-smart2.c
>>> +++ b/drivers/hwmon/nzxt-smart2.c
>>> @@ -458,7 +458,7 @@ static int send_output_report(struct drvdata *drvdata, const void *data,
>>>
>>>        ret = hid_hw_output_report(drvdata->hid, drvdata->output_buffer,
>>>                                   sizeof(drvdata->output_buffer));
>>> -     return ret < 0 ? ret : 0;
>>> +     return min(ret, 0);
>>
>> Nack, that is just confusing. ret is an error if < 0, and min obfuscates
>> that we want to return an error or 0.
>>
>> Guenter
> 
> Should I change that ternary operator to a full "if" maybe?
> Apparently, both some people and some tools read it as "min()".
> 
No, the code is good as is, using if() doesn't really make a difference,
and I _really_ don't want to encourage people to start submitting patches
to change the other 100+ instances of the same code in the kernel.

Guenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ