[PATCH] hwmon: (it87) Clamp voltage limits before multiplication
From: Zhu Jun
Date: Wed Nov 11 2026 - 01:58:10 EST
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@xxxxxxxxxxxxxxxxxxxx>
---
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