]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
hwmon: (ina238) Correctly clamp temperature
authorChris Packham <chris.packham@alliedtelesis.co.nz>
Fri, 29 Aug 2025 03:05:10 +0000 (15:05 +1200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 9 Sep 2025 17:02:37 +0000 (19:02 +0200)
[ Upstream commit 98fd069dd87386d87eaf439e3c7b5767618926d2 ]

ina238_write_temp() was attempting to clamp the user input but was
throwing away the result. Ensure that we clamp the value to the
appropriate range before it is converted into a register value.

Fixes: 0d9f596b1fe3 ("hwmon: (ina238) Modify the calculation formula to adapt to different chips")
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Link: https://lore.kernel.org/r/20250829030512.1179998-3-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 9a5fd16a4ec2a6d5a6cd5e8070d0442e1ef0135a..a2cb615fa27897928fe22b305b0c10c2e42dd367 100644 (file)
@@ -481,7 +481,7 @@ static int ina238_write_temp(struct device *dev, u32 attr, long val)
                return -EOPNOTSUPP;
 
        /* Signed */
-       regval = clamp_val(val, -40000, 125000);
+       val = clamp_val(val, -40000, 125000);
        regval = div_s64(val * 10000, data->config->temp_lsb) << data->config->temp_shift;
        regval = clamp_val(regval, S16_MIN, S16_MAX) & (0xffff << data->config->temp_shift);