Skip to content

Commit 55840b9

Browse files
committed
hwmon: (lm90) Prevent integer overflow/underflow in hysteresis calculations
Commit b50aa49 ("hwmon: (lm90) Prevent integer underflows of temperature calculations") addressed a number of underflow situations when writing temperature limits. However, it missed one situation, seen when an attempt is made to set the hysteresis value to MAX_LONG and the critical temperature limit is negative. Use clamp_val() when setting the hysteresis temperature to ensure that the provided value can never overflow or underflow. Fixes: b50aa49 ("hwmon: (lm90) Prevent integer underflows of temperature calculations") Cc: Dmitry Osipenko <[email protected]> Reviewed-by: Dmitry Osipenko <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent fce15c4 commit 55840b9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/hwmon/lm90.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,8 @@ static int lm90_set_temphyst(struct lm90_data *data, long val)
11601160
else
11611161
temp = temp_from_s8(data->temp8[LOCAL_CRIT]);
11621162

1163-
/* prevent integer underflow */
1164-
val = max(val, -128000l);
1163+
/* prevent integer overflow/underflow */
1164+
val = clamp_val(val, -128000l, 255000l);
11651165

11661166
data->temp_hyst = hyst_to_reg(temp - val);
11671167
err = i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,

0 commit comments

Comments
 (0)