mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-24 03:52:35 -04:00
hwmon: (ina238) Correctly clamp shunt voltage limit
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: eacb52f010 ("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>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user