[PATCH] hwmon: (lm80) Clamp voltage limits before rounding
From: Zhu Jun
Date: Wed Nov 11 2026 - 02:00:50 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: 1da177e4c3f41 ("Linux-2.6.12-rc2")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
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)
--
2.51.0