Skip to content

Commit 1a4aabc

Browse files
Hsin-Te Yuanrafaeljw
authored andcommitted
thermal: sysfs: Return ENODATA instead of EAGAIN for reads
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent d0b3b7b commit 1a4aabc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/thermal/thermal_sysfs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ temp_show(struct device *dev, struct device_attribute *attr, char *buf)
4040

4141
ret = thermal_zone_get_temp(tz, &temperature);
4242

43-
if (ret)
44-
return ret;
43+
if (!ret)
44+
return sprintf(buf, "%d\n", temperature);
4545

46-
return sprintf(buf, "%d\n", temperature);
46+
if (ret == -EAGAIN)
47+
return -ENODATA;
48+
49+
return ret;
4750
}
4851

4952
static ssize_t

0 commit comments

Comments
 (0)