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

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

time_to_reg() adds 50 before clamping the result. An unsigned long close
to ULONG_MAX wraps, so an excessive stop time can select zero rather
than the maximum. The same conversion is used for fan speed transition
times.

Clamp to the maximum representable duration before adding the rounding
adjustment.

Fixes: 792d376b4f3f ("hwmon: New driver for the W83795G/ADG monitoring chips")
---
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/w83795.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 96fbb0a5006f..9b0ef0c8c5b7 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -260,7 +260,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

* Re: [PATCH] hwmon: (w83795) Clamp fan control times before rounding
  2026-11-09  9:37 Zhu Jun
@ 2026-11-09  9:46 ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-09  9:46 UTC (permalink / raw)
  To: Zhu Jun; +Cc: linux-hwmon

> From: zhujun <zhujun2@cmss.chinamobile.com>
> 
> time_to_reg() adds 50 before clamping the result. An unsigned long close
> to ULONG_MAX wraps, so an excessive stop time can select zero rather
> than the maximum. The same conversion is used for fan speed transition
> times.
> 
> Clamp to the maximum representable duration before adding the rounding
> adjustment.
> 
> Fixes: 792d376b4f3f ("hwmon: New driver for the W83795G/ADG monitoring chips")

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261109093722.5508-1-zhujun2@cmss.chinamobile.com?part=1


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

* [PATCH] hwmon: (w83795) Clamp fan control times before rounding
@ 2026-11-11  6:51 Zhu Jun
  2026-11-11  6:59 ` sashiko-bot
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-11  6:51 UTC (permalink / raw)
  To: jdelvare; +Cc: linux, linux-hwmon, linux-kernel, Zhu Jun

time_to_reg() adds 50 before clamping the result. An unsigned long close
to ULONG_MAX wraps, so an excessive stop time can select zero rather
than the maximum. The same conversion is used for fan speed transition
times.

Clamp to the maximum representable duration before adding the rounding
adjustment.

Fixes: 792d376b4f3f ("hwmon: New driver for the W83795G/ADG monitoring chips")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
 drivers/hwmon/w83795.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 96fbb0a5006f..9b0ef0c8c5b7 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -260,7 +260,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

* Re: [PATCH] hwmon: (w83795) Clamp fan control times before rounding
  2026-11-11  6:51 [PATCH] hwmon: (w83795) Clamp fan control times before rounding Zhu Jun
@ 2026-11-11  6:59 ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-11  6:59 UTC (permalink / raw)
  To: Zhu Jun; +Cc: linux-hwmon

> time_to_reg() adds 50 before clamping the result. An unsigned long close
> to ULONG_MAX wraps, so an excessive stop time can select zero rather
> than the maximum. The same conversion is used for fan speed transition
> times.
> 
> Clamp to the maximum representable duration before adding the rounding
> adjustment.
> 
> Fixes: 792d376b4f3f ("hwmon: New driver for the W83795G/ADG monitoring chips")
> 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/20261111065123.17512-1-zhujun2@cmss.chinamobile.com?part=1


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

end of thread, other threads:[~2026-11-11  6:59 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:51 [PATCH] hwmon: (w83795) Clamp fan control times before rounding Zhu Jun
2026-11-11  6:59 ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-11-09  9:37 Zhu Jun
2026-11-09  9:46 ` sashiko-bot

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