* [PATCH] hwmon: (lm80) Clamp voltage limits before rounding
@ 2026-11-09 10:18 Zhu Jun
2026-11-09 10:23 ` 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 5 to the signed sysfs value before clamping the
register result. A voltage limit close to LONG_MAX can overflow and be
programmed as zero instead of the maximum.
Clamp to the 0..2550 mV register range before rounding to 10 mV units.
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/lm80.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 079f79d9b02f..9864df05d24c 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -59,7 +59,7 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
* Fixing this is just not worth it.
*/
-#define IN_TO_REG(val) (clamp_val(((val) + 5) / 10, 0, 255))
+#define IN_TO_REG(val) ((clamp_val((val), 0, 2550) + 5) / 10)
#define IN_FROM_REG(val) ((val) * 10)
static inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (lm80) Clamp voltage limits before rounding
2026-11-09 10:18 Zhu Jun
@ 2026-11-09 10:23 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-09 10:23 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> IN_TO_REG() adds 5 to the signed sysfs value before clamping the
> register result. A voltage limit close to LONG_MAX can overflow and be
> programmed as zero instead of the maximum.
>
> Clamp to the 0..2550 mV register range before rounding to 10 mV units.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109101821.17104-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] hwmon: (lm80) Clamp voltage limits before rounding
@ 2026-11-11 6:53 Zhu Jun
2026-11-11 7:01 ` 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 5 to the signed sysfs value before clamping the
register result. A voltage limit close to LONG_MAX can overflow and be
programmed as zero instead of the maximum.
Clamp to the 0..2550 mV register range before rounding to 10 mV units.
Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/lm80.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 079f79d9b02f..9864df05d24c 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -59,7 +59,7 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
* Fixing this is just not worth it.
*/
-#define IN_TO_REG(val) (clamp_val(((val) + 5) / 10, 0, 255))
+#define IN_TO_REG(val) ((clamp_val((val), 0, 2550) + 5) / 10)
#define IN_FROM_REG(val) ((val) * 10)
static inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div)
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: (lm80) Clamp voltage limits before rounding
2026-11-11 6:53 [PATCH] hwmon: (lm80) Clamp voltage limits before rounding Zhu Jun
@ 2026-11-11 7:01 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-11 7:01 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-hwmon
> IN_TO_REG() adds 5 to the signed sysfs value before clamping the
> register result. A voltage limit close to LONG_MAX can overflow and be
> programmed as zero instead of the maximum.
>
> Clamp to the 0..2550 mV register range before rounding to 10 mV units.
>
> 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/20261111065302.17721-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:01 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: (lm80) Clamp voltage limits before rounding Zhu Jun
2026-11-11 7:01 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-09 10:18 Zhu Jun
2026-11-09 10:23 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox