From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Date: Mon, 16 Dec 2019 13:17:59 +0000 (+0100)
Subject: core: use gpiod_line_event_get_fd() in gpiod_line_event_read()
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b5efbb148d34922e2744f35c2be7c8cc43efcfc9;p=qemu-gpiodev%2Flibgpiod.git

core: use gpiod_line_event_get_fd() in gpiod_line_event_read()

We can drop the redundant line state check if we directly call
gpiod_line_event_get_fd() from gpiod_line_event_read(). As opposed
to line_get_fd() it checks if the line was requested for events.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---

diff --git a/lib/core.c b/lib/core.c
index b9fd6f4..89f5465 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -1012,12 +1012,9 @@ int gpiod_line_event_read(struct gpiod_line *line,
 {
 	int fd;
 
-	if (line->state != LINE_REQUESTED_EVENTS) {
-		errno = EPERM;
+	fd = gpiod_line_event_get_fd(line);
+	if (fd < 0)
 		return -1;
-	}
-
-	fd = line_get_fd(line);
 
 	return gpiod_line_event_read_fd(fd, event);
 }