hotplug: Remove device from usb_devs before signalling its removal
authorHans de Goede <hdegoede@redhat.com>
Tue, 20 Aug 2013 13:18:59 +0000 (15:18 +0200)
committerHans de Goede <hdegoede@redhat.com>
Tue, 20 Aug 2013 13:18:59 +0000 (15:18 +0200)
If we write the remove event to the pipe before doing the list_del,
in theory another thread can process the event and unref the device before
it has been removed from usb_devs.

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

index bdf4bb7..5a00dd6 100644 (file)
@@ -567,6 +567,10 @@ void usbi_disconnect_device(struct libusb_device *dev)
        dev->attached = 0;
        usbi_mutex_unlock(&dev->lock);
 
+       usbi_mutex_lock(&ctx->usb_devs_lock);
+       list_del(&dev->list);
+       usbi_mutex_unlock(&ctx->usb_devs_lock);
+
        /* Signal that an event has occurred for this device if we support hotplug AND
         * the hotplug pipe is ready. This prevents an event from getting raised during
         * initial enumeration. libusb_handle_events will take care of dereferencing the
@@ -577,10 +581,6 @@ void usbi_disconnect_device(struct libusb_device *dev)
                        usbi_err(DEVICE_CTX(dev), "error writing hotplug message");
                }
        }
-
-       usbi_mutex_lock(&ctx->usb_devs_lock);
-       list_del(&dev->list);
-       usbi_mutex_unlock(&ctx->usb_devs_lock);
 }
 
 /* Perform some final sanity checks on a newly discovered device. If this
index 25194c6..acce2c9 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10812
+#define LIBUSB_NANO 10813