Commit 814a388e authored by Kangjie Lu's avatar Kangjie Lu Committed by Stefan Bader

hwmon: (lm80) fix a missing check of the status of SMBus read

BugLink: https://bugs.launchpad.net/bugs/1818813

[ Upstream commit c9c63915 ]

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: default avatarKangjie Lu <kjlu@umn.edu>
[groeck: One variable for return values is enough]
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 8bc8191e
...@@ -360,9 +360,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -360,9 +360,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
struct i2c_client *client = data->client; struct i2c_client *client = data->client;
unsigned long min, val; unsigned long min, val;
u8 reg; u8 reg;
int err = kstrtoul(buf, 10, &val); int rv;
if (err < 0)
return err; rv = kstrtoul(buf, 10, &val);
if (rv < 0)
return rv;
/* Save fan_min */ /* Save fan_min */
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
...@@ -390,8 +392,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -390,8 +392,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
return -EINVAL; return -EINVAL;
} }
reg = (lm80_read_value(client, LM80_REG_FANDIV) & rv = lm80_read_value(client, LM80_REG_FANDIV);
~(3 << (2 * (nr + 1)))) | (data->fan_div[nr] << (2 * (nr + 1))); 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); lm80_write_value(client, LM80_REG_FANDIV, reg);
/* Restore fan_min */ /* Restore fan_min */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment