hwmon: (adm9240) Fix overflows seen when writing into limit attributes
Subsystems (2)
Guenter Roeck
maintainerPATCH 1/4 hwmon: (adm9240) Fix overflows seen when writing into limit attributes
Module test reports:
in0_min: Suspected overflow: [3320 vs. 0]in0_max: Suspected overflow: [3320 vs. 0]in4_min: Suspected overflow: [15938 vs. 0]in4_max: Suspected overflow: [15938 vs. 0]temp1_max: Suspected overflow: [127000 vs. 0]temp1_max_hyst: Suspected overflow: [127000 vs. 0]aout_output: Suspected overflow: [1250 vs. 0]
Code analysis reveals that the overflows are caused by conversions from unsigned long to long to int, combined with multiplications on passed values.
--- drivers/hwmon/adm9240.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hwmon/adm9240.c +3 -0
@@ -98,12 +98,14 @@ static inline unsigned int IN_FROM_REG(u8 reg, int n)static inline u8 IN_TO_REG (unsigned long val,int n) { + val =clamp_val (val,0 ,INT_MAX /192 -12000 );return clamp_val (SCALE (val,192 , nom_mv[n]),0 ,255 ); }/* temperature range: -40..125, 127 disables temperature alarm */ static inline s8 TEMP_TO_REG (long val) { + val =clamp_val (val,INT_MIN +1000 ,INT_MAX -1000 );return clamp_val (SCALE (val,1 ,1000 ),-40 ,127 ); }
@@ -122,6 +124,7 @@ static inline unsigned int FAN_FROM_REG(u8 reg, u8 div)/* analog out 0..1250mV */ static inline u8 AOUT_TO_REG (unsigned long val) { + val =clamp_val (val,0 ,INT_MAX /255 -1250 );return clamp_val (SCALE (val,255 ,1250 ),0 ,255 ); }
Signature · 1 line
2.5.0
Guenter Roeck
maintainerPATCH 2/4 hwmon: (ds620) Fix overflows seen when writing temperature limits
Module test reports:
temp1_max: Suspected overflow: [160000 vs. 0]temp1_min: Suspected overflow: [160000 vs. 0]
This is seen because the values passed when writing temperature limits are unbound.
--- drivers/hwmon/ds620.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ds620.c +1 -1
@@ -166,7 +166,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,if (res)return res; - val = (val *10 /625 ) *8 ; + val = (clamp_val (val,-128000 ,128000 ) *10 /625 ) *8 ;mutex_lock (&data->update_lock); data->temp[attr->index] = val;
Signature · 1 line
2.5.0
Guenter Roeck
maintainerPATCH 3/4 hwmon: (lm93) Fix overflows seen when writing into limit attributes
In reply to Guenter RoeckModule test shows a large number of overflows, caused by missing clamps as well as various conversions between variable types.
Also fix temperature calculations for hysteresis and offset registers. For those, temperature calculations were a mix of millisecond and second based, causing reported and accepted hysteresis and offset temperatures to be widely off target.
This also changes the offset and base temperature attributes to be officially reported and set in milli-degrees C. This was already the case for the base temperature attribute, even though it was documented to be reported and set in degrees C.
--- Documentation/hwmon/lm93 | 26 +++++++++++++------------- drivers/hwmon/lm93.c | 47 +++++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 35 deletions(-)
Documentation/hwmon/lm93 +13 -13
@@ -174,25 +174,25 @@ a "0" disables it. The h/w default is 0x0f (all temperatures bound). The function y = f(x) takes a source temperature x to a PWM output y. This function of the LM93 is derived from a base temperature and a table of 12 -temperature offsets. The base temperature is expressed in degrees C in the -sysfs files temp<n>_auto_base. The offsets are expressed in cumulative -degrees C, with the value of offset <i> for temperature value <n> being +temperature offsets. The base temperature is expressed in milli-degrees C in +the sysfs files temp<n>_auto_base. The offsets are expressed in cumulative +milli-degrees C, with the value of offset <i> for temperature value <n> being contained in the file temp<n>_auto_offset<i>. E.g. if the base temperature is 40C: offset # temp<n>_auto_offset<i> range pwm 1 0 - 25.00% 2 0 - 28.57% - 3 1 40C - 41C 32.14% - 4 1 41C - 42C 35.71% - 5 2 42C - 44C 39.29% - 6 2 44C - 46C 42.86% - 7 2 48C - 50C 46.43% - 8 2 50C - 52C 50.00% - 9 2 52C - 54C 53.57% - 10 2 54C - 56C 57.14% - 11 2 56C - 58C 71.43% - 12 2 58C - 60C 85.71% + 3 500 40C - 41C 32.14% + 4 500 41C - 42C 35.71% + 5 1000 42C - 44C 39.29% + 6 1000 44C - 46C 42.86% + 7 1000 48C - 50C 46.43% + 8 1000 50C - 52C 50.00% + 9 1000 52C - 54C 53.57% + 10 1000 54C - 56C 57.14% + 11 1000 56C - 58C 71.43% + 12 1000 58C - 60C 85.71% > 60C 100.00% Valid offsets are in the range 0C <= x <= 7.5C in 0.5C increments.
drivers/hwmon/lm93.c +25 -22
110 lines not on this page · raw message
Signature · 1 line
2.5.0
Guenter Roeck
maintainerPATCH 4/4 hwmon: (smsc47m192) Fix overflows seen when writing into limit attributes
In reply to Guenter RoeckModule test reports overflows when writing into temperature and voltage limit attributes
temp1_min: Suspected overflow: [127000 vs. 0]temp1_max: Suspected overflow: [127000 vs. 0]temp1_offset: Suspected overflow: [127000 vs. 0]temp2_min: Suspected overflow: [127000 vs. 0]temp2_max: Suspected overflow: [127000 vs. 0]temp2_offset: Suspected overflow: [127000 vs. 0]temp3_min: Suspected overflow: [127000 vs. 0]temp3_max: Suspected overflow: [127000 vs. 0]temp3_offset: Suspected overflow: [127000 vs. 0]in0_min: Suspected overflow: [3320 vs. 0]in0_max: Suspected overflow: [3320 vs. 0]in4_min: Suspected overflow: [15938 vs. 0]in4_max: Suspected overflow: [15938 vs. 0]in6_min: Suspected overflow: [1992 vs. 0]in6_max: Suspected overflow: [1992 vs. 0]in7_min: Suspected overflow: [2391 vs. 0]in7_max: Suspected overflow: [2391 vs. 0]
The problem is caused by conversions from unsigned long to long and from long to int.
--- drivers/hwmon/smsc47m192.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/smsc47m192.c +2 -1
@@ -77,6 +77,7 @@ static inline unsigned int IN_FROM_REG(u8 reg, int n)static inline u8 IN_TO_REG (unsigned long val,int n) { + val =clamp_val (val,0 ,65535 );return clamp_val (SCALE (val,192 , nom_mv[n]),0 ,255 ); }
@@ -84,7 +85,7 @@ static inline u8 IN_TO_REG(unsigned long val, int n)* TEMP: 0.001 degC units (-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) {return SCALE (clamp_val (val,-128000 ,127000 ),1 ,1000 ); }
Signature · 1 line
2.5.0