hwmon: (amc6821) Fix unsigned expression compared with zero
PATCH 1/1 hwmon: (amc6821) Fix unsigned expression compared with zero
Fix the following coccicheck warning:
drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared with zero: reg > 0drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared with zero: reg > 0
--- drivers/hwmon/amc6821.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/amc6821.c +1 -1
@@ -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);
Signature · 1 line
2.25.1
Quoted 8 lines · On 11/2/22 19:27, [email protected] wrote:
Fix the following coccicheck warning:
drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared with zero: reg > 0drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared with zero: reg > 0Signed-off-by KaiLong Wang <[email protected]>
Hm. IDGI. What's wrong with comparing an unsigned value to > 0? I mean, it could be == 0 or > 0.
Please explain.
Quoted 17 lines
--- drivers/hwmon/amc6821.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/hwmon/amc6821.c +1
-1@@ -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);
Signature · 1 line
~Randy
Guenter Roeck
maintainerQuoted 10 lines · Randy Dunlap
Quoted 7 lines · On 11/2/22 19:27, [email protected] wrote:
Fix the following coccicheck warning:
drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared with zero: reg > 0drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared with zero: reg > 0
Quoted 5 lines
Quoted 1 line
Signed-off-by KaiLong Wang <[email protected]>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
Quoted 17 lines · Guenter Roeck
Quoted 10 lines · Randy Dunlap
Quoted 7 lines · On 11/2/22 19:27, [email protected] wrote:
Fix the following coccicheck warning:
drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared with zero: reg > 0drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared with zero: reg > 0Quoted 5 lines
Quoted 1 line
Signed-off-by KaiLong Wang <[email protected]>Hm. IDGI. What's wrong with comparing an unsigned value to > 0? I mean, it could be == 0 or > 0.
Please explain.
Quoted 7 lines
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.
Signature · 1 line
~Randy
Guenter Roeck
maintainerQuoted 25 lines · Randy Dunlap
Quoted 22 lines · Guenter Roeck
Quoted 10 lines · Randy Dunlap
Quoted 7 lines · On 11/2/22 19:27, [email protected] wrote:
Fix the following coccicheck warning:
drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared with zero: reg > 0drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared with zero: reg > 0Quoted 5 lines
Quoted 1 line
Signed-off-by KaiLong Wang <[email protected]>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.
Quoted 5 lines
Quoted 2 lines
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