Commit 00cab884 authored by Guenter Roeck's avatar Guenter Roeck Committed by Ben Hutchings

hwmon: (smsc47m192) Fix temperature limit and vrm write operations

commit 043572d5 upstream.

Temperature limit clamps are applied after converting the temperature
from milli-degrees C to degrees C, so either the clamp limit needs
to be specified in degrees C, not milli-degrees C, or clamping must
happen before converting to degrees C. Use the latter method to avoid
overflows.

vrm is an u8, so the written value needs to be limited to [0, 255].

Cc: Axel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Reviewed-by: default avatarJean Delvare <jdelvare@suse.de>
[bwh: Backported to 3.2:
 - Driver is not using clamp_val(); keep using SENSORS_LIMIT() for consistency
 - Driver is not using kstrtoul(); make the minimum change to set_vrm() so
   we can validate the value before assigning]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent c1dd1fd9
......@@ -84,7 +84,7 @@ static inline u8 IN_TO_REG(unsigned long val, int n)
REG: 1C/bit, two's complement */
static inline s8 TEMP_TO_REG(int val)
{
return SENSORS_LIMIT(SCALE(val, 1, 1000), -128000, 127000);
return SCALE(SENSORS_LIMIT(val, -128000, 127000), 1, 1000);
}
static inline int TEMP_FROM_REG(s8 val)
......@@ -349,7 +349,13 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct smsc47m192_data *data = dev_get_drvdata(dev);
data->vrm = simple_strtoul(buf, NULL, 10);
unsigned long val;
val = simple_strtoul(buf, NULL, 10);
if (val > 255)
return -EINVAL;
data->vrm = val;
return count;
}
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
......
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