hwmon: (lm80) fix a missing check of the status of SMBus read
PATCH v2 1/1 hwmon: (lm80) fix a missing check of the status of SMBus read
If lm80_read_value() fails, it returns a negative number instead of the correct read data. Therefore, we should avoid using the data if it fails.
The fix checks if lm80_read_value() fails, and if so, returns with the error number.
--- drivers/hwmon/lm80.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/hwmon/lm80.c +6 -2
@@ -360,6 +360,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,struct i2c_client *client = data->client;unsigned long min, val;u8 reg; +int rv;int err =kstrtoul (buf,10 , &val);if (err <0 )return err;
@@ -390,8 +391,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,return -EINVAL ; } - reg = (lm80_read_value (client,LM80_REG_FANDIV ) & - ~(3 << (2 * (nr +1 )))) | (data->fan_div[nr] << (2 * (nr +1 ))); + rv =lm80_read_value (client,LM80_REG_FANDIV ); +if (rv <0 ) +return rv; + reg = (rv & ~(3 << (2 * (nr +1 )))) + | (data->fan_div[nr] << (2 * (nr +1 )));lm80_write_value (client,LM80_REG_FANDIV , reg);/* Restore fan_min */
Signature · 1 line
2.17.1
Guenter Roeck
maintainerQuoted 9 lines · Kangjie Lu
If
lm80_read_value()fails, it returns a negative number instead of the correct read data. Therefore, we should avoid using the data if it fails.The fix checks if
lm80_read_value()fails, and if so, returns with the error number.Signed-off-by Kangjie Lu <[email protected]>---
[ change log goes here ]
Quoted 8 lines
drivers/hwmon/lm80.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/hwmon/lm80.c +0
-0
drivers/hwmon/lm80.c static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, · line 366
Quoted 7 lines
drivers/hwmon/lm80.c +1
-0@@ -360,6 +360,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,struct i2c_client *client = data->client;unsigned long min, val;u8 reg; +int rv;int err =kstrtoul (buf,10 , &val);if (err <0 )return err;
Now we have 'rv' and 'err'.
My earlier comments didn't mean to suggest that we should now have two different variables to handle errors.
Never mind, I'll fix it all up myself. No need to resend.
Guenter
Quoted 14 lines
drivers/hwmon/lm80.c +5
-2@@ -390,8 +391,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,return -EINVAL ; } - reg = (lm80_read_value (client,LM80_REG_FANDIV ) & - ~(3 << (2 * (nr +1 )))) | (data->fan_div[nr] << (2 * (nr +1 ))); + rv =lm80_read_value (client,LM80_REG_FANDIV ); +if (rv <0 ) +return rv; + reg = (rv & ~(3 << (2 * (nr +1 )))) + | (data->fan_div[nr] << (2 * (nr +1 )));lm80_write_value (client,LM80_REG_FANDIV , reg);/* Restore fan_min */