hwmon: (smsc47m192) Fix temperature limit and vrm write operations
Guenter Roeck
maintainerPATCH 1/1 hwmon: (smsc47m192) Fix temperature limit and vrm write operations
Temperature limit clamps are applied after converting the temeprature from milli-degrees C to degrees C, so the clamp limit needs to be specified in degrees C, not milli-degrees C.
vrm is an u8, so the written value needs to be clamped to [0, 255].
--- drivers/hwmon/smsc47m192.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/smsc47m192.c +2 -2
@@ -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 clamp_val (SCALE (val,1 ,1000 ),-128 ,127 ); }static inline int TEMP_FROM_REG (s8 val)
@@ -385,7 +385,7 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,if (err)return err; - data->vrm = val; + data->vrm =clamp_val (val,0 ,255 );return count; } static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
Signature · 7 lines
1.9.1 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Guenter,
Quoted 5 lines · Guenter Roeck
Temperature limit clamps are applied after converting the temeprature from milli-degrees C to degrees C, so the clamp limit needs to be specified in degrees C, not milli-degrees C.
vrm is an u8, so the written value needs to be clamped to [0, 255].
I'd rather reject out-of-range VRM values. These are discrete values, not continuous, so clamping makes no sense.
Quoted 11 lines
Cc Axel Lin <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/smsc47m192.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/hwmon/smsc47m192.c +0
-0
drivers/hwmon/smsc47m192.c static inline u8 IN_TO_REG(unsigned long val, int n) · line 90
Quoted 6 lines
drivers/hwmon/smsc47m192.c +1
-1@@ -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 clamp_val (SCALE (val,1 ,1000 ),-128 ,127 ); }
SCALE could overflow on large values. It would be safer to clamp first and then scale.
Quoted 11 lines
drivers/hwmon/smsc47m192.c +1
-1static inline int TEMP_FROM_REG (s8 val)@@ -385,7 +385,7 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,if (err)return err; - data->vrm = val; + data->vrm =clamp_val (val,0 ,255 );return count; } static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
Signature · 7 lines
Jean Delvare SUSE L3 Support _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
2014-07-18 22:35 GMT+08:00 Guenter Roeck <[email protected]>:
Quoted 7 lines
Temperature limit clamps are applied after converting the temeprature from milli-degrees C to degrees C, so the clamp limit needs to be specified in degrees C, not milli-degrees C.
vrm is an u8, so the written value needs to be clamped to [0, 255].
Cc Axel Lin <[email protected]>
Hi Guenter,
The v2 looks good to me,
Reviewed-by: Axel Lin <axel.lin at ingics.com>
Regards,
Axel
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors