* [PATCH] hwmon: (it87) Clamp voltage limits before multiplication
@ 2026-11-11 6:48 Zhu Jun
2026-11-11 6:54 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-11 6:48 UTC (permalink / raw)
To: jdelvare; +Cc: linux, linux-hwmon, linux-kernel, Zhu Jun
set_in() accepts an unsigned long, but in_to_reg() converts it to long
and multiplies it by 10 before clamping. Large positive limits can
become negative and select register zero instead of the maximum.
Keep the unsigned input type and clamp the voltage before scaling it by
the ADC resolution.
Fixes: ead8080351c9 ("hwmon: (it87) Add support for IT8732F")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
drivers/hwmon/it87.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index bbb3f9788c2e..632d98ade940 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -738,8 +738,9 @@ static int adc_lsb(const struct it87_data *data, int nr)
return lsb;
}
-static u8 in_to_reg(const struct it87_data *data, int nr, long val)
+static u8 in_to_reg(const struct it87_data *data, int nr, unsigned long val)
{
+ val = min(val, 255UL * adc_lsb(data, nr) / 10);
val = DIV_ROUND_CLOSEST(val * 10, adc_lsb(data, nr));
return clamp_val(val, 0, 255);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] hwmon: (it87) Clamp voltage limits before multiplication
@ 2026-11-09 9:27 Zhu Jun
2026-11-09 20:02 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Zhu Jun @ 2026-11-09 9:27 UTC (permalink / raw)
To: jdelvare; +Cc: linux, linux-hwmon, linux-kernel, zhujun
From: zhujun <zhujun2@cmss.chinamobile.com>
set_in() accepts an unsigned long, but in_to_reg() converts it to long
and multiplies it by 10 before clamping. Large positive limits can
become negative and select register zero instead of the maximum.
Keep the unsigned input type and clamp the voltage before scaling it by
the ADC resolution.
Fixes: ead8080351c9 ("hwmon: (it87) Add support for IT8732F")
---
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/it87.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index bbb3f9788c2e..632d98ade940 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -738,8 +738,9 @@ static int adc_lsb(const struct it87_data *data, int nr)
return lsb;
}
-static u8 in_to_reg(const struct it87_data *data, int nr, long val)
+static u8 in_to_reg(const struct it87_data *data, int nr, unsigned long val)
{
+ val = min(val, 255UL * adc_lsb(data, nr) / 10);
val = DIV_ROUND_CLOSEST(val * 10, adc_lsb(data, nr));
return clamp_val(val, 0, 255);
}
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-11 6:54 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:48 [PATCH] hwmon: (it87) Clamp voltage limits before multiplication Zhu Jun
2026-11-11 6:54 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-11-09 9:27 Zhu Jun
2026-11-09 20:02 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox