]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
thermal: sysfs: Return ENODATA instead of EAGAIN for reads
authorHsin-Te Yuan <yuanhsinte@chromium.org>
Fri, 20 Jun 2025 10:41:43 +0000 (10:41 +0000)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 3 Jul 2025 14:43:37 +0000 (16:43 +0200)
According to POSIX spec, EAGAIN returned by read with O_NONBLOCK set
means the read would block. Hence, the common implementation in
nonblocking model will poll the file when the nonblocking read returns
EAGAIN. However, when the target file is thermal zone, this mechanism
will totally malfunction because thermal zone doesn't implement sysfs
notification and thus the poll will never return.

For example, the read in Golang implemnts such method and sometimes
hangs at reading some thermal zones via sysfs.

Change to return -ENODATA instead of -EAGAIN to userspace.

Signed-off-by: Hsin-Te Yuan <yuanhsinte@chromium.org>
Link: https://patch.msgid.link/20250620-temp-v3-1-6becc6aeb66c@chromium.org
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/thermal/thermal_sysfs.c

index 24b9055a0b6c515b865e0d7e2db1d0de176ff767..d80612506a334ab739e7545cdfe984ab4dffab7c 100644 (file)
@@ -40,10 +40,13 @@ temp_show(struct device *dev, struct device_attribute *attr, char *buf)
 
        ret = thermal_zone_get_temp(tz, &temperature);
 
-       if (ret)
-               return ret;
+       if (!ret)
+               return sprintf(buf, "%d\n", temperature);
 
-       return sprintf(buf, "%d\n", temperature);
+       if (ret == -EAGAIN)
+               return -ENODATA;
+
+       return ret;
 }
 
 static ssize_t