From e99c935378acbb51c88293e9611291426fe6d89a Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Tue, 27 Mar 2012 21:12:01 +0300 Subject: [PATCH] _hiddev_open: Fix error messages Not all of the errors are caused by device open. There is actually only one error case for open and two for ioctls. Fix the error messages. Signed-off-by: Timo Kokkonen --- hiddev.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/hiddev.c b/hiddev.c index d02f463..048e3b1 100644 --- a/hiddev.c +++ b/hiddev.c @@ -115,20 +115,22 @@ static int _hiddev_open(const char *device_path, int *usage_code, { struct hiddev_devinfo device_info; struct hiddev_report_info rinfo; - int ret, error; + int ret; int fd; trace(3, "Opening device %s\n", device_path); fd = ret = open(device_path, O_RDWR); - if (fd < 0) - goto err; + if (fd < 0) { + trace(0, "Error opening device %s: %m\n", device_path); + return -1; + } rinfo.report_type = HID_REPORT_TYPE_OUTPUT; rinfo.report_id = HID_REPORT_ID_FIRST; ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo); if (ret < 0) - goto err_close; + goto err_ioctl; PRINT_FIELD(3, rinfo.report_type); PRINT_FIELD(3, rinfo.report_id); @@ -142,7 +144,7 @@ static int _hiddev_open(const char *device_path, int *usage_code, ret = ioctl(fd, HIDIOCGDEVINFO, &device_info); if (ret < 0) - goto err_close; + goto err_ioctl; PRINT_FIELD(3, device_info.bustype); PRINT_FIELD(3, device_info.busnum); @@ -164,13 +166,12 @@ static int _hiddev_open(const char *device_path, int *usage_code, return fd; +err_ioctl: + trace(0, "Error issuing ioctl: %m\n"); + err_close: close(fd); -err: - error = errno; - if (error) - printf("Error opening device %s: %s\n", device_path, - strerror(error)); + return ret; } -- 2.44.0