Skip to content

Commit

Permalink
hwmon: (smsc47m192) Fix temperature limit and vrm write operations
Browse files Browse the repository at this point in the history
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>
Cc: stable@vger.kernel.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
  • Loading branch information
Guenter Roeck committed Jul 24, 2014
1 parent 9a3c414 commit 043572d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/hwmon/smsc47m192.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static inline u8 IN_TO_REG(unsigned long val, int n)
*/
static inline s8 TEMP_TO_REG(int val)
{
return clamp_val(SCALE(val, 1, 1000), -128000, 127000);
return SCALE(clamp_val(val, -128000, 127000), 1, 1000);
}

static inline int TEMP_FROM_REG(s8 val)
Expand Down Expand Up @@ -384,6 +384,8 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
err = kstrtoul(buf, 10, &val);
if (err)
return err;
if (val > 255)
return -EINVAL;

data->vrm = val;
return count;
Expand Down

0 comments on commit 043572d

Please sign in to comment.