* [PATCH] hwmon: (w83627ehf) Clamp fan control times before rounding
@ 2026-11-09 10:16 Zhu Jun
2026-11-09 10:20 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-09 10:16 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, linux-kernel
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")
---
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/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);
}
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (w83627ehf) Clamp fan control times before rounding
2026-11-09 10:16 Zhu Jun
@ 2026-11-09 10:20 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-09 10:20 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> 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")
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109101657.16793-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] hwmon: (w83627ehf) Clamp fan control times before rounding
@ 2026-11-11 6:52 Zhu Jun
2026-11-11 7:00 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-11 6:52 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, linux-kernel, Zhu Jun
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@cmss.chinamobile.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (w83627ehf) Clamp fan control times before rounding
2026-11-11 6:52 [PATCH] hwmon: (w83627ehf) Clamp fan control times before rounding Zhu Jun
@ 2026-11-11 7:00 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-11 7:00 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> 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@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111065238.17669-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-11 7:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11 6:52 [PATCH] hwmon: (w83627ehf) Clamp fan control times before rounding Zhu Jun
2026-11-11 7:00 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-09 10:16 Zhu Jun
2026-11-09 10:20 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox