* [PATCH] hwmon: (w83781d) Clamp voltage limits before rounding
@ 2026-11-09 10:18 Zhu Jun
2026-11-09 10:22 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-09 10:18 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, linux-kernel
IN_TO_REG() adds 8 to an unsigned long before clamping. Writing
ULONG_MAX to a voltage limit therefore wraps and programs register zero
instead of 255.
Bound the input to the 0..4080 mV register range before adding the
rounding adjustment.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
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/w83781d.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 59d2b9d40920..0a820e64a7a4 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -146,7 +146,7 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
#define W83781D_DEFAULT_BETA 3435
/* Conversions */
-#define IN_TO_REG(val) clamp_val(((val) + 8) / 16, 0, 255)
+#define IN_TO_REG(val) ((clamp_val((val), 0, 4080) + 8) / 16)
#define IN_FROM_REG(val) ((val) * 16)
static inline u8
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (w83781d) Clamp voltage limits before rounding
2026-11-09 10:18 Zhu Jun
@ 2026-11-09 10:22 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-09 10:22 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> IN_TO_REG() adds 8 to an unsigned long before clamping. Writing
> ULONG_MAX to a voltage limit therefore wraps and programs register zero
> instead of 255.
>
> Bound the input to the 0..4080 mV register range before adding the
> rounding adjustment.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109101839.17181-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] hwmon: (w83781d) Clamp voltage limits before rounding
@ 2026-11-11 6:53 Zhu Jun
2026-11-11 7:04 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-11 6:53 UTC (permalink / raw)
To: linux; +Cc: linux-hwmon, linux-kernel, Zhu Jun
IN_TO_REG() adds 8 to an unsigned long before clamping. Writing
ULONG_MAX to a voltage limit therefore wraps and programs register zero
instead of 255.
Bound the input to the 0..4080 mV register range before adding the
rounding adjustment.
Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/w83781d.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 59d2b9d40920..0a820e64a7a4 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -146,7 +146,7 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
#define W83781D_DEFAULT_BETA 3435
/* Conversions */
-#define IN_TO_REG(val) clamp_val(((val) + 8) / 16, 0, 255)
+#define IN_TO_REG(val) ((clamp_val((val), 0, 4080) + 8) / 16)
#define IN_FROM_REG(val) ((val) * 16)
static inline u8
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (w83781d) Clamp voltage limits before rounding
2026-11-11 6:53 [PATCH] hwmon: (w83781d) Clamp voltage limits before rounding Zhu Jun
@ 2026-11-11 7:04 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-11 7:04 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> IN_TO_REG() adds 8 to an unsigned long before clamping. Writing
> ULONG_MAX to a voltage limit therefore wraps and programs register zero
> instead of 255.
>
> Bound the input to the 0..4080 mV register range before adding the
> rounding adjustment.
>
> Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
> 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/20261111065307.17735-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:04 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:53 [PATCH] hwmon: (w83781d) Clamp voltage limits before rounding Zhu Jun
2026-11-11 7:04 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-09 10:18 Zhu Jun
2026-11-09 10:22 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox