]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
hwmon: (ina238) Correctly clamp shunt voltage limit
authorGuenter Roeck <linux@roeck-us.net>
Fri, 29 Aug 2025 13:49:51 +0000 (06:49 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 9 Sep 2025 17:02:38 +0000 (19:02 +0200)
[ Upstream commit bd7e7bc2cc2024035dfbc8239c9f4d8675793445 ]

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@digi.com>
Cc: Chris Packham <chris.packham@alliedtelesis.co.nz>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hwmon/ina238.c

index a2cb615fa27897928fe22b305b0c10c2e42dd367..0562f9a4dcf12c3b1a482f51280dd30eeecd8e6f 100644 (file)
@@ -300,7 +300,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: