From a164646a582594c8b6870213b93d8386f868bb23 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Fri, 21 Jan 2022 10:46:25 +0000 Subject: [PATCH] Fix handling of ENOENT on opening hiddev The original Jabra code returned a boolean from doListDev(), but I made it return the fd. Which means returning zero for ENOENT probably isn't a good idea any more. Make it return -1 for that case too. --- jabra.c | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/jabra.c b/jabra.c index 42c7db9..80f7359 100644 --- a/jabra.c +++ b/jabra.c @@ -246,36 +246,32 @@ static int doListDev(char *path) { char name[128]; int version; - if ((fd = open(path, O_RDONLY)) != -1) { - if (ioctl(fd, HIDIOCGDEVINFO, &devinfo) == -1) { - perror("ioctl HIDIOCGDEVINFO"); - close(fd); - return -1; - } - if (ioctl(fd, HIDIOCGNAME(sizeof(name)), name) == -1) { - perror("ioctl HIDIOCGNAME"); - close(fd); - return -1; - } - if (ioctl(fd, HIDIOCGVERSION, &version) == -1) { - perror("ioctl HIDIOCGVERSION"); - close(fd); - return -1; - } - if (devinfo.vendor != JABRA_VID && - devinfo.vendor != PLANTRONICS_VID) { - close(fd); - return -1; - } + fd = open(path, O_RDONLY); + if (fd == -1) return fd; - } - if (errno == ENOENT) { - return 0; + if (ioctl(fd, HIDIOCGDEVINFO, &devinfo) == -1) { + perror("ioctl HIDIOCGDEVINFO"); + close(fd); + return -1; + } + if (ioctl(fd, HIDIOCGNAME(sizeof(name)), name) == -1) { + perror("ioctl HIDIOCGNAME"); + close(fd); + return -1; + } + if (ioctl(fd, HIDIOCGVERSION, &version) == -1) { + perror("ioctl HIDIOCGVERSION"); + close(fd); + return -1; + } + if (devinfo.vendor != JABRA_VID && + devinfo.vendor != PLANTRONICS_VID) { + close(fd); + return -1; } - perror("ioctl HIDIOCGVERSION"); - return -1; + return fd; } static void writeUsage(int fd, unsigned report_type, unsigned page, unsigned code, __s32 value) { -- 2.50.1