core: Add ctx to the active context list before backend->init
authorHans de Goede <hdegoede@redhat.com>
Thu, 16 May 2013 14:32:33 +0000 (16:32 +0200)
committerHans de Goede <hdegoede@redhat.com>
Thu, 16 May 2013 15:18:32 +0000 (17:18 +0200)
As soon as backend->init has completed hotplug events may fire, and they
will not get processed on the created context until it has been added
to the active_context list.

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

index 280bb21..e3f9f51 100644 (file)
@@ -1767,6 +1767,14 @@ int API_EXPORTED libusb_init(libusb_context **context)
        list_init(&ctx->open_devs);
        list_init(&ctx->hotplug_cbs);
 
+       usbi_mutex_static_lock(&active_contexts_lock);
+       if (first_init) {
+               first_init = 0;
+               list_init (&active_contexts_list);
+       }
+       list_add (&ctx->list, &active_contexts_list);
+       usbi_mutex_static_unlock(&active_contexts_lock);
+
        if (usbi_backend->init) {
                r = usbi_backend->init(ctx);
                if (r)
@@ -1789,21 +1797,15 @@ int API_EXPORTED libusb_init(libusb_context **context)
        }
        usbi_mutex_static_unlock(&default_context_lock);
 
-       usbi_mutex_static_lock(&active_contexts_lock);
-       if (first_init) {
-               first_init = 0;
-               list_init (&active_contexts_list);
-       }
-
-       list_add (&ctx->list, &active_contexts_list);
-       usbi_mutex_static_unlock(&active_contexts_lock);
-
        return 0;
 
 err_destroy_mutex:
        usbi_mutex_destroy(&ctx->open_devs_lock);
        usbi_mutex_destroy(&ctx->usb_devs_lock);
 err_free_ctx:
+       usbi_mutex_static_lock(&active_contexts_lock);
+       list_del (&ctx->list);
+       usbi_mutex_static_unlock(&active_contexts_lock);
        usbi_mutex_lock(&ctx->usb_devs_lock);
        list_for_each_entry_safe(dev, next, &ctx->usb_devs, list, struct libusb_device) {
                list_del(&dev->list);
index fce37d3..4a6dca1 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10676
+#define LIBUSB_NANO 10677