diff options
author | Hans de Goede <hdegoede@redhat.com> | 2013-08-20 15:18:59 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-08-20 15:18:59 +0200 |
commit | fad4a18c8a55947a9c4f1a427427b176e053a991 (patch) | |
tree | 7c70c114a1513a206f75faff64d6e64c45dec351 /libusb/core.c | |
parent | 11335a2620a39a403b17a7809735712ec7a64a2c (diff) | |
download | libusb-fad4a18c8a55947a9c4f1a427427b176e053a991.tar.gz |
hotplug: Remove device from usb_devs before signalling its removal
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>
Diffstat (limited to 'libusb/core.c')
-rw-r--r-- | libusb/core.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/libusb/core.c b/libusb/core.c index bdf4bb7..5a00dd6 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -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 |