hwmon: (pt5161l) Fix invalid temperature reading
authorCosmo Chou <chou.cosmo@gmail.com>
Mon, 19 Aug 2024 10:46:30 +0000 (18:46 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 27 Aug 2024 03:58:05 +0000 (20:58 -0700)
The temperature reading function was using a signed long for the ADC
code, which could lead to mishandling of invalid codes on 32-bit
platforms. This allowed out-of-range ADC codes to be incorrectly
interpreted as valid values and used in temperature calculations.

Change adc_code to u32 to ensure that invalid ADC codes are correctly
identified on all platforms.

Fixes: 1b2ca93cd059 ("hwmon: Add driver for Astera Labs PT5161L retimer")
Signed-off-by: Cosmo Chou <chou.cosmo@gmail.com>
Message-ID: <20240819104630.2375441-1-chou.cosmo@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/pt5161l.c

index b0d58a26d499d0e541f6ee78daa4a3922742a9c2..a9f0b23f9e76e65c100217a829dd00783098c8ad 100644 (file)
@@ -427,7 +427,7 @@ static int pt5161l_read(struct device *dev, enum hwmon_sensor_types type,
        struct pt5161l_data *data = dev_get_drvdata(dev);
        int ret;
        u8 buf[8];
-       long adc_code;
+       u32 adc_code;
 
        switch (attr) {
        case hwmon_temp_input:
@@ -449,7 +449,7 @@ static int pt5161l_read(struct device *dev, enum hwmon_sensor_types type,
 
                adc_code = buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0];
                if (adc_code == 0 || adc_code >= 0x3ff) {
-                       dev_dbg(dev, "Invalid adc_code %lx\n", adc_code);
+                       dev_dbg(dev, "Invalid adc_code %x\n", adc_code);
                        return -EIO;
                }