]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hwmon: (tps23861) Fix reporting of negative temperatures
authorMurad Masimov <m.masimov@maxima.ru>
Thu, 21 Nov 2024 17:36:03 +0000 (20:36 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Sat, 23 Nov 2024 17:49:03 +0000 (09:49 -0800)
Negative temperatures are reported as large positive temperatures
due to missing sign extension from unsigned int to long. Cast unsigned
raw register values to signed before performing the calculations
to fix the problem.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: fff7b8ab2255 ("hwmon: add Texas Instruments TPS23861 driver")
Signed-off-by: Murad Masimov <m.masimov@maxima.ru>
Message-ID: <20241121173604.2021-1-m.masimov@maxima.ru>
[groeck: Updated subject and description]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/tps23861.c

index dfcfb09d9f3cdf3a7f133b49742fdf6d3db6ba73..80fb03f30c302ddae311adb03acad2e487176fa6 100644 (file)
@@ -132,7 +132,7 @@ static int tps23861_read_temp(struct tps23861_data *data, long *val)
        if (err < 0)
                return err;
 
-       *val = (regval * TEMPERATURE_LSB) - 20000;
+       *val = ((long)regval * TEMPERATURE_LSB) - 20000;
 
        return 0;
 }