[PATCH] hwmon: (w83793) Clamp temperatures before rounding
From: Zhu Jun
Date: Wed Nov 11 2026 - 02:03:59 EST
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@xxxxxxxxxxxxxxxxxxxx>
---
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