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:
committed by
Brendan Le Foll
parent
dd807308ac
commit
ee05b49ea2
@@ -151,6 +151,10 @@ mraa_gpio_wait_interrupt(int fd)
|
|||||||
unsigned char c;
|
unsigned char c;
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
|
|
||||||
|
if (fd <= 0) {
|
||||||
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
// setup poll on POLLPRI
|
// setup poll on POLLPRI
|
||||||
pfd.fd = fd;
|
pfd.fd = fd;
|
||||||
pfd.events = POLLPRI;
|
pfd.events = POLLPRI;
|
||||||
@@ -159,10 +163,6 @@ mraa_gpio_wait_interrupt(int fd)
|
|||||||
lseek (fd, 0, SEEK_SET);
|
lseek (fd, 0, SEEK_SET);
|
||||||
read (fd, &c, 1);
|
read (fd, &c, 1);
|
||||||
|
|
||||||
if (fd <= 0) {
|
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for it forever or until pthread_cancel
|
// Wait for it forever or until pthread_cancel
|
||||||
// poll is a cancelable point like sleep()
|
// poll is a cancelable point like sleep()
|
||||||
int x = poll (&pfd, 1, -1);
|
int x = poll (&pfd, 1, -1);
|
||||||
|
|||||||
Reference in New Issue
Block a user