[linux,dev-6.12,v1 8/9] hwmon: (ina238) Correctly clamp shunt voltage limit
Peter Yin
peteryin.openbmc at gmail.com
Wed Sep 17 16:01:33 AEST 2025
From: Guenter Roeck <linux at roeck-us.net>
When clamping a register value, the result needs to be masked against the
register size. This was missing, resulting in errors when trying to write
negative limits. Fix by masking the clamping result against the register
size.
Fixes: eacb52f010a80 ("hwmon: Driver for Texas Instruments INA238")
Cc: Nathan Rossi <nathan.rossi at digi.com>
Cc: Chris Packham <chris.packham at alliedtelesis.co.nz>
Signed-off-by: Guenter Roeck <linux at roeck-us.net>
(cherry picked from commit bd7e7bc2cc2024035dfbc8239c9f4d8675793445)
---
drivers/hwmon/ina238.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c
index 4d3dc018ead9..c6b2734898d0 100644
--- a/drivers/hwmon/ina238.c
+++ b/drivers/hwmon/ina238.c
@@ -379,7 +379,7 @@ static int ina238_write_in(struct device *dev, u32 attr, int channel,
regval = clamp_val(val, -163, 163);
regval = (regval * 1000 * 4) /
(INA238_SHUNT_VOLTAGE_LSB * data->gain);
- regval = clamp_val(regval, S16_MIN, S16_MAX);
+ regval = clamp_val(regval, S16_MIN, S16_MAX) & 0xffff;
switch (attr) {
case hwmon_in_max:
--
2.43.0
More information about the openbmc
mailing list