Private
Public Access
2
0

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 <jtrulson@ics.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Jon Trulson
2015-02-20 13:35:26 +00:00
committed by Brendan Le Foll
parent dd807308ac
commit ee05b49ea2

View File

@@ -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);