summaryrefslogtreecommitdiffstats
path: root/tools/iio
diff options
context:
space:
mode:
authorHartmut Knaack <knaack.h@gmx.de>2015-05-31 14:39:49 +0200
committerJonathan Cameron <jic23@kernel.org>2015-05-31 18:34:05 +0200
commit5fdb8c6127c3c594360fb5f2959a724809c0032e (patch)
treee4d479970a72bb4ca332f9515e1ef8ff7cd4a0e7 /tools/iio
parenttools:iio: save errno first (diff)
downloadlinux-5fdb8c6127c3c594360fb5f2959a724809c0032e.tar.xz
linux-5fdb8c6127c3c594360fb5f2959a724809c0032e.zip
tools:iio:iio_event_monitor: save right errno
Move up error handling code to preserve the errno coming from ioctl(), before it may be changed by close(). Signed-off-by: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'tools/iio')
-rw-r--r--tools/iio/iio_event_monitor.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
index f6fdab48d340..578390db1bec 100644
--- a/tools/iio/iio_event_monitor.c
+++ b/tools/iio/iio_event_monitor.c
@@ -275,15 +275,17 @@ int main(int argc, char **argv)
}
ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
-
- close(fd);
-
if (ret == -1 || event_fd == -1) {
ret = -errno;
fprintf(stdout, "Failed to retrieve event fd\n");
+ if (close(fd) == -1)
+ perror("Failed to close character device file");
+
goto error_free_chrdev_name;
}
+ close(fd);
+
while (true) {
ret = read(event_fd, &event, sizeof(event));
if (ret == -1) {