From e98bd8653a1d8d7500ae751b8c6f4ca455f4e48a Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Mon, 21 Dec 2015 15:48:28 +0000 Subject: [PATCH] iio.c: Check return of fd before using ioctl Signed-off-by: Brendan Le Foll --- src/iio/iio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/iio/iio.c b/src/iio/iio.c index 1d02983..26dba06 100644 --- a/src/iio/iio.c +++ b/src/iio/iio.c @@ -443,8 +443,12 @@ mraa_iio_event_poll(mraa_iio_context dev, struct iio_event_data* data) snprintf(bu, MAX_SIZE, IIO_SLASH_DEV "%d", dev->num); fd = open(bu, 0); - ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd); - close(fd); + if (fd != -1) { + ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd); + close(fd); + } else { + return MRAA_ERROR_UNSPECIFIED; + } if (ret == -1 || event_fd == -1) return MRAA_ERROR_UNSPECIFIED; -- 2.7.4