Skip to content

Commit

Permalink
hwmon: (lm80) fix a missing check of the status of SMBus read
Browse files Browse the repository at this point in the history
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 <kjlu@umn.edu>
[groeck: One variable for return values is enough]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Kangjie Lu authored and Guenter Roeck committed Dec 21, 2018
1 parent f9facc2 commit c9c6391
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions drivers/hwmon/lm80.c
Original file line number Diff line number Diff line change
@@ -360,9 +360,11 @@ 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 err = kstrtoul(buf, 10, &val);
if (err < 0)
return err;
int rv;

rv = kstrtoul(buf, 10, &val);
if (rv < 0)
return rv;

/* Save fan_min */
mutex_lock(&data->update_lock);
@@ -390,8 +392,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 */

0 comments on commit c9c6391

Please sign in to comment.