Commit 98fd069d authored by Chris Packham's avatar Chris Packham Committed by Guenter Roeck
Browse files

hwmon: (ina238) Correctly clamp temperature



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: 0d9f596b ("hwmon: (ina238) Modify the calculation formula to adapt to different chips")
Signed-off-by: default avatarChris Packham <chris.packham@alliedtelesis.co.nz>
Link: https://lore.kernel.org/r/20250829030512.1179998-3-chris.packham@alliedtelesis.co.nz


Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 1180c79f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -572,7 +572,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);