[PATCH] hwmon: (lm80) Clamp voltage limits before rounding
From: Zhu Jun
Date: Mon Nov 09 2026 - 05:21:48 EST
IN_TO_REG() adds 5 to the signed sysfs value before clamping the
register result. A voltage limit close to LONG_MAX can overflow and be
programmed as zero instead of the maximum.
Clamp to the 0..2550 mV register range before rounding to 10 mV units.
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/lm80.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 079f79d9b02f..9864df05d24c 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -59,7 +59,7 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
* Fixing this is just not worth it.
*/
-#define IN_TO_REG(val) (clamp_val(((val) + 5) / 10, 0, 255))
+#define IN_TO_REG(val) ((clamp_val((val), 0, 2550) + 5) / 10)
#define IN_FROM_REG(val) ((val) * 10)
static inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0