linux: Move check for a device being added twice to linux_enumerate_device
authorHans de Goede <hdegoede@redhat.com>
Thu, 16 May 2013 15:02:08 +0000 (17:02 +0200)
committerHans de Goede <hdegoede@redhat.com>
Thu, 16 May 2013 15:18:33 +0000 (17:18 +0200)
It is possible for a device to show up between the hotplug code starting to
listen for new devices, and the enumeration of existing devices. This will
cause a device to get enumerated twice.

The next patch in this series adds a different code path which can cause
a device to be enumerated twice, this patch therefor moves the check for
this to linux_enumerate_device, so that this will get caught in all cases.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb/os/linux_usbfs.c
libusb/version_nano.h

index 7b9840f..0159f81 100644 (file)
@@ -1155,6 +1155,12 @@ int linux_enumerate_device(struct libusb_context *ctx,
        usbi_dbg("busnum %d devaddr %d session_id %ld", busnum, devaddr,
                session_id);
 
+       if (usbi_get_device_by_session_id(ctx, session_id)) {
+               /* device already exists in the context */
+               usbi_dbg("session_id %ld already exists", session_id);
+               return LIBUSB_SUCCESS;
+       }
+
        usbi_dbg("allocating new device for %d/%d (session %ld)",
                 busnum, devaddr, session_id);
        dev = usbi_alloc_device(ctx, session_id);
@@ -1187,12 +1193,6 @@ void linux_hotplug_enumerate(uint8_t busnum, uint8_t devaddr, const char *sys_na
        usbi_mutex_static_lock(&active_contexts_lock);
        usbi_mutex_static_lock(&hotplug_lock);
        list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
-               if (usbi_get_device_by_session_id(ctx, busnum << 8 | devaddr)) {
-                       /* device already exists in the context */
-                       usbi_dbg("device already exists in context");
-                       continue;
-               }
-
                linux_enumerate_device(ctx, busnum, devaddr, sys_name);
        }
        usbi_mutex_static_unlock(&hotplug_lock);
index 0033866..9d2fc4a 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10681
+#define LIBUSB_NANO 10682