* [PATCH] hwmon: (w83791d) Clamp voltage limits before rounding
@ 2026-11-09 10:19 Zhu Jun
2026-11-09 10:21 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-09 10:19 UTC (permalink / raw)
To: m.hulsman; +Cc: linux, linux-hwmon, linux-kernel
IN_TO_REG() adds the rounding adjustment before checking the register
range. For an unsigned sysfs input such as ULONG_MAX, this addition
wraps and selects zero instead of the maximum voltage limit.
Clamp the millivolt value to the representable range before rounding to
16 mV register units.
Fixes: 9873964d6eb2 ("[PATCH] HWMON: w83791d: New hardware monitoring driver for the Winbond W83791D")
---
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/w83791d.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 8bb457326c0b..41c73fca388d 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -207,7 +207,7 @@ static inline int w83791d_write(struct i2c_client *client, u8 reg, u8 value)
* in mV as would be measured on the chip input pin, need to just
* multiply/divide by 16 to translate from/to register values.
*/
-#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 u8 fan_to_reg(long rpm, int div)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (w83791d) Clamp voltage limits before rounding
2026-11-09 10:19 [PATCH] hwmon: (w83791d) Clamp voltage limits before rounding Zhu Jun
@ 2026-11-09 10:21 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-09 10:21 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> IN_TO_REG() adds the rounding adjustment before checking the register
> range. For an unsigned sysfs input such as ULONG_MAX, this addition
> wraps and selects zero instead of the maximum voltage limit.
>
> Clamp the millivolt value to the representable range before rounding to
> 16 mV register units.
>
> Fixes: 9873964d6eb2 ("[PATCH] HWMON: w83791d: New hardware monitoring driver for the Winbond W83791D")
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109101900.17256-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] hwmon: (w83791d) 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: m.hulsman; +Cc: linux, linux-hwmon, linux-kernel, Zhu Jun
IN_TO_REG() adds the rounding adjustment before checking the register
range. For an unsigned sysfs input such as ULONG_MAX, this addition
wraps and selects zero instead of the maximum voltage limit.
Clamp the millivolt value to the representable range before rounding to
16 mV register units.
Fixes: 9873964d6eb2 ("[PATCH] HWMON: w83791d: New hardware monitoring driver for the Winbond W83791D")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/w83791d.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 8bb457326c0b..41c73fca388d 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -207,7 +207,7 @@ static inline int w83791d_write(struct i2c_client *client, u8 reg, u8 value)
* in mV as would be measured on the chip input pin, need to just
* multiply/divide by 16 to translate from/to register values.
*/
-#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 u8 fan_to_reg(long rpm, int div)
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (w83791d) Clamp voltage limits before rounding
2026-11-11 6:53 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 the rounding adjustment before checking the register
> range. For an unsigned sysfs input such as ULONG_MAX, this addition
> wraps and selects zero instead of the maximum voltage limit.
>
> Clamp the millivolt value to the representable range before rounding to
> 16 mV register units.
>
> Fixes: 9873964d6eb2 ("[PATCH] HWMON: w83791d: New hardware monitoring driver for the Winbond W83791D")
> 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/20261111065313.17748-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-09 10:19 [PATCH] hwmon: (w83791d) Clamp voltage limits before rounding Zhu Jun
2026-11-09 10:21 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-11 6:53 Zhu Jun
2026-11-11 7:04 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox