summaryrefslogtreecommitdiff
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2021-11-17 20:51:47 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-12-29 14:28:47 +0300
commitd105f30bea9104c590a9e5b495cb8a49bdfe405f (patch)
treecfeebb302e89dcc2142ed817058685ca27d09686 /drivers/hwmon
parent4b8f0e940972ac34128efbe6cfb904356d088bfe (diff)
downloadlinux-d105f30bea9104c590a9e5b495cb8a49bdfe405f.tar.xz
hwmon: (lm90) Prevent integer overflow/underflow in hysteresis calculations
[ Upstream commit 55840b9eae5367b5d5b29619dc2fb7e4596dba46 ] Commit b50aa49638c7 ("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: b50aa49638c7 ("hwmon: (lm90) Prevent integer underflows of temperature calculations") Cc: Dmitry Osipenko <digetx@gmail.com> Reviewed-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm90.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index d40e3bb801d0..f6e6c7c6c73f 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1143,8 +1143,8 @@ static int lm90_set_temphyst(struct lm90_data *data, long val)
else
temp = temp_from_s8(data->temp8[LOCAL_CRIT]);
- /* prevent integer underflow */
- val = max(val, -128000l);
+ /* prevent integer overflow/underflow */
+ val = clamp_val(val, -128000l, 255000l);
data->temp_hyst = hyst_to_reg(temp - val);
err = i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,