]> git.karo-electronics.de Git - linux-beck.git/commitdiff
hwmon: (lm87) Fix overflow seen when writing voltage limit attributes
authorGuenter Roeck <linux@roeck-us.net>
Mon, 5 Dec 2016 02:16:02 +0000 (18:16 -0800)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 12 Dec 2016 19:33:42 +0000 (11:33 -0800)
Writes into voltage limit attributes can overflow due to an unbound
multiplication.

Reviewed-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/lm87.c

index 81cb898245a107d66ae2dae9f87e9d9d39fdad84..13cca3606e060cf441022587cdfa203313bb232a 100644 (file)
@@ -121,7 +121,7 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C };
 
 #define IN_FROM_REG(reg, scale)        (((reg) * (scale) + 96) / 192)
 #define IN_TO_REG(val, scale)  ((val) <= 0 ? 0 : \
-                                (val) * 192 >= (scale) * 255 ? 255 : \
+                                (val) >= (scale) * 255 / 192 ? 255 : \
                                 ((val) * 192 + (scale) / 2) / (scale))
 
 #define TEMP_FROM_REG(reg)     ((reg) * 1000)