[PATCH] hwmon: (w83791d) Clamp voltage limits before rounding
From: Zhu Jun
Date: Mon Nov 09 2026 - 05:36:19 EST
IN_TO_REG() adds the rounding adjustment before checking the register
range. For an unsigned sysfs input such as ULONG_MAX, this addition
wraps and selects zero instead of the maximum voltage limit.
Clamp the millivolt value to the representable range before rounding to
16 mV register units.
Fixes: 9873964d6eb2 ("[PATCH] HWMON: w83791d: New hardware monitoring driver for the Winbond W83791D")
---
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/w83791d.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 8bb457326c0b..41c73fca388d 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -207,7 +207,7 @@ static inline int w83791d_write(struct i2c_client *client, u8 reg, u8 value)
* in mV as would be measured on the chip input pin, need to just
* multiply/divide by 16 to translate from/to register values.
*/
-#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 u8 fan_to_reg(long rpm, int div)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0