mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwmon: (amc6821) Fix unsigned expression compared with zero
@ 2022-11-03  2:27 wangkailong
  2022-11-03  2:59 ` Randy Dunlap
  0 siblings, 1 reply; 5+ messages in thread
From: wangkailong @ 2022-11-03  2:27 UTC (permalink / raw)
  To: jdelvare, linux; +Cc: linux-hwmon, linux-kernel

Fix the following coccicheck warning:

drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared
with zero: reg > 0
drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared
with zero: reg > 0

Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
---
 drivers/hwmon/amc6821.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index 3bfd12ff4b3c..1f5382f8d52b 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -166,7 +166,7 @@ static struct amc6821_data *amc6821_update_device(struct device *dev)
 	struct amc6821_data *data = dev_get_drvdata(dev);
 	struct i2c_client *client = data->client;
 	int timeout = HZ;
-	u8 reg;
+	int reg;
 	int i;
 
 	mutex_lock(&data->update_lock);
-- 
2.25.1

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

* Re: [PATCH] hwmon: (amc6821) Fix unsigned expression compared with zero
  2022-11-03  2:27 [PATCH] hwmon: (amc6821) Fix unsigned expression compared with zero wangkailong
@ 2022-11-03  2:59 ` Randy Dunlap
  2022-11-03 14:17   ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Randy Dunlap @ 2022-11-03  2:59 UTC (permalink / raw)
  To: wangkailong, jdelvare, linux; +Cc: linux-hwmon, linux-kernel



On 11/2/22 19:27, wangkailong@jari.cn wrote:
> Fix the following coccicheck warning:
> 
> drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared
> with zero: reg > 0
> drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared
> with zero: reg > 0
> 
> Signed-off-by: KaiLong Wang <wangkailong@jari.cn>

Hm. IDGI. What's wrong with comparing an unsigned value to > 0?
I mean, it could be == 0 or > 0.
Please explain.

> ---
>  drivers/hwmon/amc6821.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
> index 3bfd12ff4b3c..1f5382f8d52b 100644
> --- a/drivers/hwmon/amc6821.c
> +++ b/drivers/hwmon/amc6821.c
> @@ -166,7 +166,7 @@ static struct amc6821_data *amc6821_update_device(struct device *dev)
>  	struct amc6821_data *data = dev_get_drvdata(dev);
>  	struct i2c_client *client = data->client;
>  	int timeout = HZ;
> -	u8 reg;
> +	int reg;
>  	int i;
>  
>  	mutex_lock(&data->update_lock);

-- 
~Randy

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

* Re: [PATCH] hwmon: (amc6821) Fix unsigned expression compared with zero
  2022-11-03  2:59 ` Randy Dunlap
@ 2022-11-03 14:17   ` Guenter Roeck
  2022-11-03 15:03     ` Randy Dunlap
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2022-11-03 14:17 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: wangkailong, jdelvare, linux-hwmon, linux-kernel

On Wed, Nov 02, 2022 at 07:59:06PM -0700, Randy Dunlap wrote:
> 
> 
> On 11/2/22 19:27, wangkailong@jari.cn wrote:
> > Fix the following coccicheck warning:
> > 
> > drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared
> > with zero: reg > 0
> > drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared
> > with zero: reg > 0
> > 
> > Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
> 
> Hm. IDGI. What's wrong with comparing an unsigned value to > 0?
> I mean, it could be == 0 or > 0.
> Please explain.

I don't get it either. The real problem with this driver is that error
returns from i2c functions are not checked. However, that problem is not
fixed by this patch. That means the patch would change behavior without
fixing the actual problem.

I wonder what kind of (broken) compiler or analyzer produces above errors.
We'll have to watch out for similar broken "fixes".

Guenter

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

* Re: [PATCH] hwmon: (amc6821) Fix unsigned expression compared with zero
  2022-11-03 14:17   ` Guenter Roeck
@ 2022-11-03 15:03     ` Randy Dunlap
  2022-11-03 15:25       ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Randy Dunlap @ 2022-11-03 15:03 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: wangkailong, jdelvare, linux-hwmon, linux-kernel



On 11/3/22 07:17, Guenter Roeck wrote:
> On Wed, Nov 02, 2022 at 07:59:06PM -0700, Randy Dunlap wrote:
>>
>>
>> On 11/2/22 19:27, wangkailong@jari.cn wrote:
>>> Fix the following coccicheck warning:
>>>
>>> drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared
>>> with zero: reg > 0
>>> drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared
>>> with zero: reg > 0
>>>
>>> Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
>>
>> Hm. IDGI. What's wrong with comparing an unsigned value to > 0?
>> I mean, it could be == 0 or > 0.
>> Please explain.
> 
> I don't get it either. The real problem with this driver is that error
> returns from i2c functions are not checked. However, that problem is not
> fixed by this patch. That means the patch would change behavior without
> fixing the actual problem.
> 
> I wonder what kind of (broken) compiler or analyzer produces above errors.
> We'll have to watch out for similar broken "fixes".

It says above that it's a coccicheck warning.

-- 
~Randy

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

* Re: [PATCH] hwmon: (amc6821) Fix unsigned expression compared with zero
  2022-11-03 15:03     ` Randy Dunlap
@ 2022-11-03 15:25       ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2022-11-03 15:25 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: wangkailong, jdelvare, linux-hwmon, linux-kernel

On Thu, Nov 03, 2022 at 08:03:35AM -0700, Randy Dunlap wrote:
> 
> 
> On 11/3/22 07:17, Guenter Roeck wrote:
> > On Wed, Nov 02, 2022 at 07:59:06PM -0700, Randy Dunlap wrote:
> >>
> >>
> >> On 11/2/22 19:27, wangkailong@jari.cn wrote:
> >>> Fix the following coccicheck warning:
> >>>
> >>> drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared
> >>> with zero: reg > 0
> >>> drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared
> >>> with zero: reg > 0
> >>>
> >>> Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
> >>
> >> Hm. IDGI. What's wrong with comparing an unsigned value to > 0?
> >> I mean, it could be == 0 or > 0.
> >> Please explain.
> > 
> > I don't get it either. The real problem with this driver is that error
> > returns from i2c functions are not checked. However, that problem is not
> > fixed by this patch. That means the patch would change behavior without
> > fixing the actual problem.
> > 
> > I wonder what kind of (broken) compiler or analyzer produces above errors.
> > We'll have to watch out for similar broken "fixes".
> 
> It says above that it's a coccicheck warning.
> 

I see, unsigned_lesser_than_zero.cocci. It actually complains that an
unsigned variable is used to hold the return code of a function which
returns an int. In other words, it really tries to warn that the error
return code from that function is not or not properly checked.
The message is misleading for that situation.

Guenter

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

end of thread, other threads:[~2022-11-03 15:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03  2:27 [PATCH] hwmon: (amc6821) Fix unsigned expression compared with zero wangkailong
2022-11-03  2:59 ` Randy Dunlap
2022-11-03 14:17   ` Guenter Roeck
2022-11-03 15:03     ` Randy Dunlap
2022-11-03 15:25       ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®