Skip to content

Commit 6bc941d

Browse files
groeckgregkh
authored andcommitted
hwmon: (ina238) Correctly clamp shunt voltage limit
[ Upstream commit bd7e7bc ] 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: eacb52f ("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>
1 parent 765c243 commit 6bc941d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/hwmon/ina238.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int ina238_write_in(struct device *dev, u32 attr, int channel,
300300
regval = clamp_val(val, -163, 163);
301301
regval = (regval * 1000 * 4) /
302302
(INA238_SHUNT_VOLTAGE_LSB * data->gain);
303-
regval = clamp_val(regval, S16_MIN, S16_MAX);
303+
regval = clamp_val(regval, S16_MIN, S16_MAX) & 0xffff;
304304

305305
switch (attr) {
306306
case hwmon_in_max:

0 commit comments

Comments
 (0)