* [PATCH] hwmon: (w83793) Clamp temperatures before rounding
@ 2026-11-11 6:52 Zhu Jun
2026-11-11 7:03 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-11 6:52 UTC (permalink / raw)
To: r.marek; +Cc: linux, linux-hwmon, linux-kernel, Zhu Jun
TEMP_TO_REG() applies its rounding adjustment to an unrestricted long.
LONG_MIN minus 500 and LONG_MAX plus 500 overflow before the register
range is enforced, potentially selecting the opposite end of that range.
Clamp the input to the requested temperature range before adding the
rounding adjustment.
Fixes: 6800c3d027b4 ("hwmon: New Winbond W83793 hardware monitoring driver")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/w83793.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index e1f2708b5db6..012544b044bb 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -199,6 +199,7 @@ static inline long TEMP_FROM_REG(s8 reg)
static inline s8 TEMP_TO_REG(long val, s8 min, s8 max)
{
+ val = clamp_val(val, min * 1000, max * 1000);
return clamp_val((val + (val < 0 ? -500 : 500)) / 1000, min, max);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] hwmon: (w83793) Clamp temperatures before rounding
@ 2026-11-09 10:18 Zhu Jun
2026-11-09 10:24 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-09 10:18 UTC (permalink / raw)
To: r.marek; +Cc: linux, linux-hwmon, linux-kernel
TEMP_TO_REG() applies its rounding adjustment to an unrestricted long.
LONG_MIN minus 500 and LONG_MAX plus 500 overflow before the register
range is enforced, potentially selecting the opposite end of that range.
Clamp the input to the requested temperature range before adding the
rounding adjustment.
Fixes: 6800c3d027b4 ("hwmon: New Winbond W83793 hardware monitoring driver")
---
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/w83793.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index e1f2708b5db6..012544b044bb 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -199,6 +199,7 @@ static inline long TEMP_FROM_REG(s8 reg)
static inline s8 TEMP_TO_REG(long val, s8 min, s8 max)
{
+ val = clamp_val(val, min * 1000, max * 1000);
return clamp_val((val + (val < 0 ? -500 : 500)) / 1000, min, max);
}
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-11 7:03 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: (w83793) Clamp temperatures before rounding Zhu Jun
2026-11-11 7:03 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-09 10:18 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