[PATCH] tools: gpio: gpio-watch: do not clobber errno on read error
From: Gu Bin
Date: Fri Nov 13 2026 - 00:06:24 EST
gpio-watch reads line change events from a gpiochip character device
and reports a read() error or short read with perror(), which prints
strerror(errno). If read() fails, say with EINTR, the inner
if (rd != sizeof(chg))
errno = EIO;
replaces the real errno with EIO, so the message always reports
"Input/output error" instead of the actual cause.
Only synthesize EIO for short reads (rd >= 0), keeping the errno
that read() set when it failed.
Fixes: 33f0c47b8fb4 ("tools: gpio: implement gpio-watch")
Signed-off-by: Gu Bin <gubin@xxxxxxxxxxxxxxxxxxxx>
---
tools/gpio/gpio-watch.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/gpio/gpio-watch.c b/tools/gpio/gpio-watch.c
index 41e76d2441922..e7733cedcf0d6 100644
--- a/tools/gpio/gpio-watch.c
+++ b/tools/gpio/gpio-watch.c
@@ -64,7 +64,7 @@ int main(int argc, char **argv)
memset(&chg, 0, sizeof(chg));
rd = read(pfd.fd, &chg, sizeof(chg));
if (rd < 0 || rd != sizeof(chg)) {
- if (rd != sizeof(chg))
+ if (rd >= 0 && rd != sizeof(chg))
errno = EIO;
perror("error reading line change event");
--
2.50.1.windows.1