* [PATCH] hwmon: (it87) Clamp temperatures before rounding
@ 2026-11-09 10:17 Zhu Jun
2026-11-09 10:24 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-09 10:17 UTC (permalink / raw)
To: jdelvare; +Cc: linux, linux-hwmon, linux-kernel
TEMP_TO_REG() adds or subtracts 500 before clamping the result. Values
near LONG_MAX or LONG_MIN can overflow, causing a high temperature limit
to select the lowest register value, or vice versa.
Clamp the requested temperature to the signed 8-bit range before
rounding to whole degrees.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
Validation: x86-64 and i386 driver objects built with W=1.
Source-extracted boundary tests passed on both word sizes;
the corresponding test fails on the base revision. I/O is mocked.
No physical sensor or booted-kernel testing was available.
OpenAI Codex assisted analysis, code, tests and changelog drafting.
Please review and add your own Signed-off-by before submitting.
drivers/hwmon/it87.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index b8ad1ed043b3..036e0b7ce01b 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -771,8 +771,8 @@ static inline u16 FAN16_TO_REG(long rpm)
#define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
1350000 / ((val) * 2))
-#define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
- ((val) + 500) / 1000), -128, 127))
+#define TEMP_TO_REG(val) \
+ DIV_ROUND_CLOSEST(clamp_val((val), -128000, 127000), 1000)
#define TEMP_FROM_REG(val) ((val) * 1000)
static u8 pwm_to_reg(const struct it87_data *data, long val)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (it87) Clamp temperatures before rounding
2026-11-09 10:17 Zhu Jun
@ 2026-11-09 10:24 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-09 10:24 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> TEMP_TO_REG() adds or subtracts 500 before clamping the result. Values
> near LONG_MAX or LONG_MIN can overflow, causing a high temperature limit
> to select the lowest register value, or vice versa.
>
> Clamp the requested temperature to the signed 8-bit range before
> rounding to whole degrees.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109101743.16955-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] hwmon: (it87) Clamp temperatures before rounding
@ 2026-11-11 6:52 Zhu Jun
2026-11-11 7:01 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-11 6:52 UTC (permalink / raw)
To: jdelvare; +Cc: linux, linux-hwmon, linux-kernel, Zhu Jun
TEMP_TO_REG() adds or subtracts 500 before clamping the result. Values
near LONG_MAX or LONG_MIN can overflow, causing a high temperature limit
to select the lowest register value, or vice versa.
Clamp the requested temperature to the signed 8-bit range before
rounding to whole degrees.
Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/it87.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index b8ad1ed043b3..036e0b7ce01b 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -771,8 +771,8 @@ static inline u16 FAN16_TO_REG(long rpm)
#define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
1350000 / ((val) * 2))
-#define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
- ((val) + 500) / 1000), -128, 127))
+#define TEMP_TO_REG(val) \
+ DIV_ROUND_CLOSEST(clamp_val((val), -128000, 127000), 1000)
#define TEMP_FROM_REG(val) ((val) * 1000)
static u8 pwm_to_reg(const struct it87_data *data, long val)
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (it87) Clamp temperatures before rounding
2026-11-11 6:52 [PATCH] hwmon: (it87) Clamp temperatures before rounding Zhu Jun
@ 2026-11-11 7:01 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-11 7:01 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> TEMP_TO_REG() adds or subtracts 500 before clamping the result. Values
> near LONG_MAX or LONG_MIN can overflow, causing a high temperature limit
> to select the lowest register value, or vice versa.
>
> Clamp the requested temperature to the signed 8-bit range before
> rounding to whole degrees.
>
> Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111065252.17695-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-11 7:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11 6:52 [PATCH] hwmon: (it87) Clamp temperatures before rounding Zhu Jun
2026-11-11 7:01 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-09 10:17 Zhu Jun
2026-11-09 10:24 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox