From ee05b49ea2e23ebe4e5c0cde96bd5dba6d593570 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 20 Feb 2015 13:35:26 +0000 Subject: [PATCH] gpio.c: check fd before attempting to use it mraa_gpio_wait_interrupt needs to check fd before using it Signed-off-by: Jon Trulson Signed-off-by: Brendan Le Foll --- src/gpio/gpio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gpio/gpio.c b/src/gpio/gpio.c index bbcccba..78327d8 100644 --- a/src/gpio/gpio.c +++ b/src/gpio/gpio.c @@ -151,6 +151,10 @@ mraa_gpio_wait_interrupt(int fd) unsigned char c; struct pollfd pfd; + if (fd <= 0) { + return MRAA_ERROR_INVALID_RESOURCE; + } + // setup poll on POLLPRI pfd.fd = fd; pfd.events = POLLPRI; @@ -159,10 +163,6 @@ mraa_gpio_wait_interrupt(int fd) lseek (fd, 0, SEEK_SET); read (fd, &c, 1); - if (fd <= 0) { - return MRAA_ERROR_INVALID_RESOURCE; - } - // Wait for it forever or until pthread_cancel // poll is a cancelable point like sleep() int x = poll (&pfd, 1, -1);