From: Guenter Roeck <linux@roeck-us.net>
To: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Cc: Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
Dmitry Osipenko <digetx@gmail.com>
Subject: [PATCH 2/5] hwmon: (lm90) Prevent integer overflow/underflow in hysteresis calculations
Date: Fri, 10 Dec 2021 12:01:33 -0800 [thread overview]
Message-ID: <20211210200136.1662127-3-linux@roeck-us.net> (raw)
In-Reply-To: <20211210200136.1662127-1-linux@roeck-us.net>
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>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/lm90.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index b05d73c4fbe2..72969ea83d82 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1160,8 +1160,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,
--
2.33.0
next prev parent reply other threads:[~2021-12-10 20:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-10 20:01 [PATCH 0/5] hwmon: (lm90) Various fixes Guenter Roeck
2021-12-10 20:01 ` [PATCH 1/5] hwmon: (lm90) Fix usage of CONFIG2 register in detect function Guenter Roeck
2021-12-10 20:01 ` Guenter Roeck [this message]
2021-12-10 21:08 ` [PATCH 2/5] hwmon: (lm90) Prevent integer overflow/underflow in hysteresis calculations Dmitry Osipenko
2021-12-10 20:01 ` [PATCH 3/5] hwmon: (lm90) Drop critical attribute support for MAX6654 Guenter Roeck
2021-12-10 20:01 ` [PATCH 4/5] hwmom: (lm90) Fix citical alarm status for MAX6680/MAX6681 Guenter Roeck
2021-12-10 20:01 ` [PATCH 5/5] hwmon: (lm90) Do not report 'busy' status bit as alarm Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211210200136.1662127-3-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=digetx@gmail.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox