* [PATCH v2] hwmon: (pt5161l) Fix invalid temperature reading
@ 2024-08-19 10:46 Cosmo Chou
2024-08-27 3:58 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Cosmo Chou @ 2024-08-19 10:46 UTC (permalink / raw)
To: linux, jdelvare, chou.cosmo; +Cc: linux-hwmon, linux-kernel, cosmo.chou
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>
---
Change log:
v2:
- Fix build warnings of dev_dbg().
---
drivers/hwmon/pt5161l.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/pt5161l.c b/drivers/hwmon/pt5161l.c
index b0d58a26d499..a9f0b23f9e76 100644
--- a/drivers/hwmon/pt5161l.c
+++ b/drivers/hwmon/pt5161l.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] hwmon: (pt5161l) Fix invalid temperature reading
2024-08-19 10:46 [PATCH v2] hwmon: (pt5161l) Fix invalid temperature reading Cosmo Chou
@ 2024-08-27 3:58 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2024-08-27 3:58 UTC (permalink / raw)
To: Cosmo Chou; +Cc: jdelvare, linux-hwmon, linux-kernel, cosmo.chou
On Mon, Aug 19, 2024 at 06:46:30PM +0800, Cosmo Chou wrote:
> 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>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-27 3:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-19 10:46 [PATCH v2] hwmon: (pt5161l) Fix invalid temperature reading Cosmo Chou
2024-08-27 3:58 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox