[PATCH] hwmon: (it87) Clamp voltage limits before multiplication
From: Zhu Jun
Date: Mon Nov 09 2026 - 04:28:04 EST
From: zhujun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
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