linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: Use min() instead of doing it manually
@ 2021-12-27 11:36 Jiapeng Chong
  2021-12-27 15:43 ` Guenter Roeck
  0 siblings, 1 reply; 4+ messages in thread
From: Jiapeng Chong @ 2021-12-27 11:36 UTC (permalink / raw)
  To: mezin.alexander
  Cc: jdelvare, linux, linux-hwmon, linux-kernel, Jiapeng Chong, Abaci Robot

Eliminate following coccicheck warning:

./drivers/hwmon/nzxt-smart2.c:461:12-13: WARNING opportunity for min().

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.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);
 }
 
 static int set_pwm(struct drvdata *drvdata, int channel, long val)
-- 
2.20.1.7.g153144c


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: Use min() instead of doing it manually
  2021-12-27 11:36 [PATCH] hwmon: Use min() instead of doing it manually Jiapeng Chong
@ 2021-12-27 15:43 ` Guenter Roeck
  2021-12-28  0:18   ` Aleksandr Mezin
  0 siblings, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2021-12-27 15:43 UTC (permalink / raw)
  To: Jiapeng Chong, mezin.alexander
  Cc: jdelvare, linux-hwmon, linux-kernel, Abaci Robot

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@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: Use min() instead of doing it manually
  2021-12-27 15:43 ` Guenter Roeck
@ 2021-12-28  0:18   ` Aleksandr Mezin
  2021-12-28  0:36     ` Guenter Roeck
  0 siblings, 1 reply; 4+ messages in thread
From: Aleksandr Mezin @ 2021-12-28  0:18 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Jiapeng Chong, Jean Delvare, linux-hwmon, linux-kernel, Abaci Robot

On Mon, Dec 27, 2021 at 9:43 PM Guenter Roeck <linux@roeck-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@linux.alibaba.com>
> > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.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()".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: Use min() instead of doing it manually
  2021-12-28  0:18   ` Aleksandr Mezin
@ 2021-12-28  0:36     ` Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2021-12-28  0:36 UTC (permalink / raw)
  To: Aleksandr Mezin
  Cc: Jiapeng Chong, Jean Delvare, linux-hwmon, linux-kernel, Abaci Robot

On 12/27/21 4:18 PM, Aleksandr Mezin wrote:
> On Mon, Dec 27, 2021 at 9:43 PM Guenter Roeck <linux@roeck-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@linux.alibaba.com>
>>> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-28  0:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-27 11:36 [PATCH] hwmon: Use min() instead of doing it manually Jiapeng Chong
2021-12-27 15:43 ` Guenter Roeck
2021-12-28  0:18   ` Aleksandr Mezin
2021-12-28  0:36     ` Guenter Roeck

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