Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH] hwmon: (w83793) Clamp fan control times before rounding
@ 2026-11-09  9:35 Zhu Jun
  2026-11-09  9:48 ` sashiko-bot
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-09  9:35 UTC (permalink / raw)
  To: r.marek; +Cc: zhujun, linux, linux-hwmon, linux-kernel

From: zhujun <zhujun2@cmss.chinamobile.com>

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




^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] hwmon: (w83793) Clamp fan control times before rounding
@ 2026-11-11  6:51 Zhu Jun
  2026-11-11  7:06 ` sashiko-bot
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-11  6:51 UTC (permalink / raw)
  To: r.marek; +Cc: linux, linux-hwmon, linux-kernel, Zhu Jun

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")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
 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)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-11  7:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09  9:35 [PATCH] hwmon: (w83793) Clamp fan control times before rounding Zhu Jun
2026-11-09  9:48 ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-11-11  6:51 Zhu Jun
2026-11-11  7:06 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox