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

zhangjiao2 posted 1 patch 1 month ago
samples/timers/hpet_example.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[PATCH] samples: timers: hpet_example: Fix fcntl() error check
Posted by zhangjiao2 1 month ago
From: zhang jiao <zhangjiao2@cmss.chinamobile.com>

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@cmss.chinamobile.com>
---
 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