[PATCH] hwmon: (w83781d) Clamp voltage limits before rounding
From: Zhu Jun
Date: Mon Nov 09 2026 - 05:21:26 EST
IN_TO_REG() adds 8 to an unsigned long before clamping. Writing
ULONG_MAX to a voltage limit therefore wraps and programs register zero
instead of 255.
Bound the input to the 0..4080 mV register range before adding the
rounding adjustment.
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/w83781d.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 59d2b9d40920..0a820e64a7a4 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -146,7 +146,7 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
#define W83781D_DEFAULT_BETA 3435
/* Conversions */
-#define IN_TO_REG(val) clamp_val(((val) + 8) / 16, 0, 255)
+#define IN_TO_REG(val) ((clamp_val((val), 0, 4080) + 8) / 16)
#define IN_FROM_REG(val) ((val) * 16)
static inline u8
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0