diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-08-05 18:54:04 +0200 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-06 02:49:12 +0200 |
commit | 539a719f9b90f37b934b90ad52be646b9e74a9f6 (patch) | |
tree | b3dc5d7646eea41985183f9c10d57d12e6b5f12c /drivers/hwmon/emc6w201.c | |
parent | hwmon: (ads1015) Fix out-of-bounds array access (diff) | |
download | linux-539a719f9b90f37b934b90ad52be646b9e74a9f6.tar.xz linux-539a719f9b90f37b934b90ad52be646b9e74a9f6.zip |
hwmon: (emc6w201) Fix temperature limit range
Temperature limit range is [-127, 127], not [-127, 128].
The wrong range caused a bad limit to be written into the chip
if the limit was set to a value of 128 degrees C or above.
Also use DIV_ROUND_CLOSEST instead of a plain divide operation
to reduce the rounding error when writing temperature limits.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Diffstat (limited to 'drivers/hwmon/emc6w201.c')
-rw-r--r-- | drivers/hwmon/emc6w201.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c index e87da902f3ae..ada90716448d 100644 --- a/drivers/hwmon/emc6w201.c +++ b/drivers/hwmon/emc6w201.c @@ -252,12 +252,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, if (err < 0) return err; - val /= 1000; + val = DIV_ROUND_CLOSEST(val, 1000); reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr) : EMC6W201_REG_TEMP_HIGH(nr); mutex_lock(&data->update_lock); - data->temp[sf][nr] = clamp_val(val, -127, 128); + data->temp[sf][nr] = clamp_val(val, -127, 127); err = emc6w201_write8(client, reg, data->temp[sf][nr]); mutex_unlock(&data->update_lock); |