hwmon: (lm78) Fix overflow problems seen when writing large limits
Subsystems (2)
Guenter Roeck
maintainerPATCH 1/1 hwmon: (lm78) Fix overflow problems seen when writing large limits
On platforms with sizeof(int) < sizeof(long), writing a temperature limit larger than MAXINT will result in unpredictable limit values written to the chip. Avoid auto-conversion from long to int to fix the problem.
--- drivers/hwmon/lm78.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/lm78.c +1 -1
@@ -108,7 +108,7 @@ static inline int FAN_FROM_REG(u8 val, int div)* TEMP: mC (-128C to +127C) * REG: 1C/bit, two's complement */ -static inline s8 TEMP_TO_REG (int val) +static inline s8 TEMP_TO_REG (long val) {int nval =clamp_val (val,-128000 ,127000 ) ;return nval <0 ? (nval -500 ) /1000 : (nval +500 ) /1000 ;
Signature · 7 lines
1.9.1 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
2014-07-30 11:52 GMT+08:00 Guenter Roeck <[email protected]>:
Quoted 7 lines
On platforms with sizeof(int) < sizeof(long), writing a temperature limit larger than MAXINT will result in unpredictable limit values written to the chip. Avoid auto-conversion from long to int to fix the problem.
Cc Axel Lin <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
The patch looks good to me, so
BTW, seems other drivers have similar issue:
$ grep "TEMP_TO_REG(int" drivers/hwmon/*.c drivers/hwmon/dme1737.c:static inline int TEMP_TO_REG(int val) drivers/hwmon/lm77.c:static inline s16 LM77_TEMP_TO_REG(int temp) drivers/hwmon/lm78.c:static inline s8 TEMP_TO_REG(int val) drivers/hwmon/lm92.c:static inline s16 TEMP_TO_REG(int val) drivers/hwmon/sis5595.c:static inline s8 TEMP_TO_REG(int val) drivers/hwmon/smsc47m192.c:static inline s8 TEMP_TO_REG(int val)
Axel
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerQuoted 11 lines · Axel Lin
2014-07-30 11:52 GMT+08:00 Guenter Roeck <[email protected]>:
Quoted 7 lines
On platforms with sizeof(int) < sizeof(long), writing a temperature limit larger than MAXINT will result in unpredictable limit values written to the chip. Avoid auto-conversion from long to int to fix the problem.
Cc Axel Lin <[email protected]>Signed-off-by Guenter Roeck <[email protected]>The patch looks good to me, so
Reviewed-by Axel Lin <[email protected]>
Thanks!
Quoted 9 lines
BTW, seems other drivers have similar issue:
$ grep "TEMP_TO_REG(int" drivers/hwmon/*.c drivers/hwmon/dme1737.c:static inline int TEMP_TO_REG(int val) drivers/hwmon/lm77.c:static inline s16 LM77_TEMP_TO_REG(int temp) drivers/hwmon/lm78.c:static inline s8 TEMP_TO_REG(int val) drivers/hwmon/lm92.c:static inline s16 TEMP_TO_REG(int val) drivers/hwmon/sis5595.c:static inline s8 TEMP_TO_REG(int val) drivers/hwmon/smsc47m192.c:static inline s8 TEMP_TO_REG(int val)
I usually find those problems when running module tests; one of the tests explicitly tries to trigger this kind of overflow (long -> int). Works pretty well...
Add lm85 to the list, with several issues all over the place. I am right now working on that one. The smsc47m192 problem is already fixed; I found that when I tested your patch. Patches for the others are welcome :-). Those would take a bit to apply, though, since I'll want to have module tests to ensure that the drivers don't have any other problems.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors