hwmon: (drivetemp) Return -ENODATA for invalid temperatures
authorGuenter Roeck <linux@roeck-us.net>
Thu, 9 Apr 2020 03:37:30 +0000 (20:37 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 12 Apr 2020 22:12:51 +0000 (15:12 -0700)
Holger Hoffstätte observed that Samsung 850 Pro may return invalid
temperatures for a short period of time after resume. Return -ENODATA
to userspace if this is observed.

Fixes:  5b46903d8bf3 ("hwmon: Driver for disk and solid state drives with temperature sensors")
Reported-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Cc: Holger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/drivetemp.c

index 370d0c7..9179460 100644 (file)
@@ -264,12 +264,18 @@ static int drivetemp_get_scttemp(struct drivetemp_data *st, u32 attr, long *val)
                return err;
        switch (attr) {
        case hwmon_temp_input:
+               if (!temp_is_valid(buf[SCT_STATUS_TEMP]))
+                       return -ENODATA;
                *val = temp_from_sct(buf[SCT_STATUS_TEMP]);
                break;
        case hwmon_temp_lowest:
+               if (!temp_is_valid(buf[SCT_STATUS_TEMP_LOWEST]))
+                       return -ENODATA;
                *val = temp_from_sct(buf[SCT_STATUS_TEMP_LOWEST]);
                break;
        case hwmon_temp_highest:
+               if (!temp_is_valid(buf[SCT_STATUS_TEMP_HIGHEST]))
+                       return -ENODATA;
                *val = temp_from_sct(buf[SCT_STATUS_TEMP_HIGHEST]);
                break;
        default: