[PATCH] hwmon: (w83793) Clamp fan control times before rounding

From: Zhu Jun

Date: Mon Nov 09 2026 - 04:38:44 EST


From: zhujun <zhujun2@xxxxxxxxxxxxxxxxxxxx>

TIME_TO_REG() adds 50 to an unsigned long before applying its upper
bound. Writing ULONG_MAX to pwm1_stop_time therefore wraps and selects
zero instead of the maximum duration.

Clamp the duration to 25500 ms before rounding to the 100 ms register
units.

Fixes: 6800c3d027b4 ("hwmon: New Winbond W83793 hardware monitoring driver")
---
Validation: x86-64 and i386 driver objects built with W=1.
Source-extracted boundary tests passed on 32-bit and 64-bit;
the corresponding test fails on the base revision. I/O is mocked.
No physical sensor hardware or booted-kernel test was available.
OpenAI Codex assisted analysis, code, tests and changelog drafting.
The human submitter must review and add their Signed-off-by.

drivers/hwmon/w83793.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index b1d390904fe4..b5d47c00c445 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -189,7 +189,7 @@ static inline unsigned long TIME_FROM_REG(u8 reg)

static inline u8 TIME_TO_REG(unsigned long val)
{
- return clamp_val((val + 50) / 100, 0, 0xff);
+ return (min(val, 25500UL) + 50) / 100;
}

static inline long TEMP_FROM_REG(s8 reg)

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0