Skip to content

Commit 7bbc079

Browse files
cchouxgroeck
authored andcommitted
hwmon: (pt5161l) Fix invalid temperature reading
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: 1b2ca93 ("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>
1 parent 9efaebc commit 7bbc079

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/hwmon/pt5161l.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static int pt5161l_read(struct device *dev, enum hwmon_sensor_types type,
427427
struct pt5161l_data *data = dev_get_drvdata(dev);
428428
int ret;
429429
u8 buf[8];
430-
long adc_code;
430+
u32 adc_code;
431431

432432
switch (attr) {
433433
case hwmon_temp_input:
@@ -449,7 +449,7 @@ static int pt5161l_read(struct device *dev, enum hwmon_sensor_types type,
449449

450450
adc_code = buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0];
451451
if (adc_code == 0 || adc_code >= 0x3ff) {
452-
dev_dbg(dev, "Invalid adc_code %lx\n", adc_code);
452+
dev_dbg(dev, "Invalid adc_code %x\n", adc_code);
453453
return -EIO;
454454
}
455455

0 commit comments

Comments
 (0)