hwmon: Use min() instead of doing it manually
PATCH 1/1 hwmon: Use min() instead of doing it manually
Eliminate following coccicheck warning:
./drivers/hwmon/nzxt-smart2.c:461:12-13: WARNING opportunity for min().
--- drivers/hwmon/nzxt-smart2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/nzxt-smart2.c +1 -1
@@ -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)
Signature · 1 line
2.20.1.7.g153144c
Quoted 15 lines · Jiapeng Chong
Eliminate following coccicheck warning:
./drivers/hwmon/nzxt-smart2.c:461:12-13: WARNING opportunity for
min().Reported-by Abaci Robot <[email protected]>Signed-off-by Jiapeng Chong <[email protected]>--- drivers/hwmon/nzxt-smart2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hwmon/nzxt-smart2.c +0
-0
drivers/hwmon/nzxt-smart2.c static int send_output_report(struct drvdata *drvdata, const void *data, · line 461
Quoted 5 lines
drivers/hwmon/nzxt-smart2.c +1
-1@@ -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
Quoted 26 lines · Guenter Roeck
Quoted 15 lines · Jiapeng Chong
Eliminate following coccicheck warning:
./drivers/hwmon/nzxt-smart2.c:461:12-13: WARNING opportunity for
min().Reported-by Abaci Robot <[email protected]>Signed-off-by Jiapeng Chong <[email protected]>--- drivers/hwmon/nzxt-smart2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hwmon/nzxt-smart2.c +0
-0drivers/hwmon/nzxt-smart2.c static int send_output_report(struct drvdata *drvdata, const void *data, · line 461
Quoted 5 lines
drivers/hwmon/nzxt-smart2.c +1
-1@@ -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.
Quoted 1 line
Guenter
Should I change that ternary operator to a full "if" maybe? Apparently, both some people and some tools read it as "min()".
Guenter Roeck
maintainerQuoted 27 lines · Aleksandr Mezin
Quoted 26 lines · Guenter Roeck
Quoted 15 lines · Jiapeng Chong
Eliminate following coccicheck warning:
./drivers/hwmon/nzxt-smart2.c:461:12-13: WARNING opportunity for
min().Reported-by Abaci Robot <[email protected]>Signed-off-by Jiapeng Chong <[email protected]>--- drivers/hwmon/nzxt-smart2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hwmon/nzxt-smart2.c +0
-0drivers/hwmon/nzxt-smart2.c static int send_output_report(struct drvdata *drvdata, const void *data, · line 461
Quoted 5 lines
drivers/hwmon/nzxt-smart2.c +1
-1@@ -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.
Quoted 5 lines
Quoted 1 line
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