[PATCH] samples: timers: hpet_example: Fix fcntl() error check

From: zhangjiao2

Date: Wed Aug 26 2026 - 05:21:18 EST


From: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>

fcntl() returns -1 on error, but hpet_fasync() compared the return
value against 1, so fcntl failures were never detected. Use "< 0"
instead.

Signed-off-by: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>
---
samples/timers/hpet_example.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/samples/timers/hpet_example.c b/samples/timers/hpet_example.c
index f1cb622f6ec0..0be3f2418af6 100644
--- a/samples/timers/hpet_example.c
+++ b/samples/timers/hpet_example.c
@@ -247,10 +247,10 @@ hpet_fasync(int argc, const char **argv)
return;
}

-
- if ((fcntl(fd, F_SETOWN, getpid()) == 1) ||
- ((value = fcntl(fd, F_GETFL)) == 1) ||
- (fcntl(fd, F_SETFL, value | O_ASYNC) == 1)) {
+ value = fcntl(fd, F_GETFL);
+ if ((fcntl(fd, F_SETOWN, getpid()) < 0) ||
+ (value < 0) ||
+ (fcntl(fd, F_SETFL, value | O_ASYNC) < 0)) {
fprintf(stderr, "hpet_fasync: fcntl failed\n");
goto out;
}
--
2.33.0