[PATCH] tools: gpio-watch: Preserve line event read errors

From: Zhu Jun

Date: Fri Nov 20 2026 - 01:18:49 EST


The short-read check sets errno to EIO even when read() returns -1,
hiding errors such as EINTR. Set EIO only for a nonnegative short
read and keep the original errno for a failed read.

Fixes: 33f0c47b8fb4 ("tools: gpio: implement gpio-watch")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
tools/gpio/gpio-watch.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/gpio/gpio-watch.c b/tools/gpio/gpio-watch.c
index 41e76d244192..a77f6d0cd0a0 100644
--- a/tools/gpio/gpio-watch.c
+++ b/tools/gpio/gpio-watch.c
@@ -63,8 +63,8 @@ int main(int argc, char **argv)
} else if (ret > 0) {
memset(&chg, 0, sizeof(chg));
rd = read(pfd.fd, &chg, sizeof(chg));
- if (rd < 0 || rd != sizeof(chg)) {
- if (rd != sizeof(chg))
+ if (rd != sizeof(chg)) {
+ if (rd >= 0)
errno = EIO;

perror("error reading line change event");