Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

docs: gpio: prefer pread(2) for interrupt reading

In legacy sysfs GPIO, when using poll(2) on the sysfs GPIO value for
state change awaiting, a subsequent read(2) is required for consuming
the event, which the doc recommends the use of lseek(2) or
close-and-reopen to reset the file offset afterwards.

The recommendations however, require at least 2 syscalls to consume
the event. Gladly, use of pread(2) require only 1 syscall for the
consumption. Let's advertise this usage by prioritizing its placement.

Signed-off-by: Huichun Feng <foxhoundsk.tw@gmail.com>
Link: https://lore.kernel.org/r/20240609173728.2950808-1-foxhoundsk.tw@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

Huichun Feng and committed by
Bartosz Golaszewski
7f1e45f4 54a687cd

+4 -3
+4 -3
Documentation/userspace-api/gpio/sysfs.rst
··· 97 97 poll(2) will return whenever the interrupt was triggered. If 98 98 you use poll(2), set the events POLLPRI and POLLERR. If you 99 99 use select(2), set the file descriptor in exceptfds. After 100 - poll(2) returns, either lseek(2) to the beginning of the sysfs 101 - file and read the new value or close the file and re-open it 102 - to read the value. 100 + poll(2) returns, use pread(2) to read the value at offset 101 + zero. Alternatively, either lseek(2) to the beginning of the 102 + sysfs file and read the new value or close the file and 103 + re-open it to read the value. 103 104 104 105 "edge" ... 105 106 reads as either "none", "rising", "falling", or