]> www.infradead.org Git - users/dwmw2/pidgin-headset.git/commitdiff
Fix handling of ENOENT on opening hiddev master
authorDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 21 Jan 2022 10:46:25 +0000 (10:46 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 21 Jan 2022 10:46:25 +0000 (10:46 +0000)
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

diff --git a/jabra.c b/jabra.c
index 42c7db94749f4a63e4dbaaa4146bb878b204892b..80f7359651041e3130694049fad36e51b6b9817a 100644 (file)
--- 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) {