[PATCH] hwmon: (w83627ehf) Clamp fan control times before rounding
From: Zhu Jun
Date: Wed Nov 11 2026 - 01:52:51 EST
The fan time stores pass an unsigned long to step_time_to_reg(), which
takes unsigned int. Large values can be truncated or overflow when the
rounding adjustment is added. For example, 4294967295 ms selects
register 1 instead of 255.
Keep the input as unsigned long and bound it to the maximum duration
before applying the PWM or DC mode conversion.
Fixes: 08c79950a047 ("hwmon: Add fan speed control features to w83627ehf")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
drivers/hwmon/w83627ehf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 9c08ab662dc6..5bcb0a5fd095 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -258,8 +258,9 @@ static inline unsigned int step_time_from_reg(u8 reg, u8 mode)
return mode ? 100 * reg : 400 * reg;
}
-static inline u8 step_time_to_reg(unsigned int msec, u8 mode)
+static inline u8 step_time_to_reg(unsigned long msec, u8 mode)
{
+ msec = min(msec, 255UL * (mode ? 100 : 400));
return clamp_val((mode ? (msec + 50) / 100 : (msec + 200) / 400),
1, 255);
}
--
2.51.0