core: Fixes order InterfaceAdded 96/204896/1
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 7 Feb 2018 11:35:07 +0000 (09:35 -0200)
committerAmit Purwar <amit.purwar@samsung.com>
Mon, 15 Apr 2019 03:25:32 +0000 (08:55 +0530)
Registering on the callback of MGMT_OP_READ_ADV_FEATURES causes
InterfacesAdded to be reschedule after the device objects which causes
tools such as PulseAudio to consider it invalid.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1534857

Change-Id: I5e485ccbeb9d0cd81b0a34bbe970306333ef948e
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
src/advertising.c

index e6bb180..0705220 100644 (file)
@@ -1033,14 +1033,6 @@ static void read_adv_features_callback(uint8_t status, uint16_t length,
        if (manager->max_ads == 0)
                return;
 
-       if (!g_dbus_register_interface(btd_get_dbus_connection(),
-                                       adapter_get_path(manager->adapter),
-                                       LE_ADVERTISING_MGR_IFACE, methods,
-                                       NULL, properties, manager, NULL)) {
-               error("Failed to register " LE_ADVERTISING_MGR_IFACE);
-               return;
-       }
-
        /* Reset existing instances */
        if (feat->num_instances)
                remove_advertising(manager, 0);
@@ -1062,19 +1054,29 @@ static struct btd_adv_manager *manager_create(struct btd_adapter *adapter)
        }
 
        manager->mgmt_index = btd_adapter_get_index(adapter);
+       manager->clients = queue_new();
+       manager->supported_flags = MGMT_ADV_FLAG_LOCAL_NAME;
+
+       if (!g_dbus_register_interface(btd_get_dbus_connection(),
+                                       adapter_get_path(manager->adapter),
+                                       LE_ADVERTISING_MGR_IFACE, methods,
+                                       NULL, properties, manager, NULL)) {
+               error("Failed to register " LE_ADVERTISING_MGR_IFACE);
+               goto fail;
+       }
 
        if (!mgmt_send(manager->mgmt, MGMT_OP_READ_ADV_FEATURES,
                                manager->mgmt_index, 0, NULL,
                                read_adv_features_callback, manager, NULL)) {
                error("Failed to read advertising features");
-               manager_destroy(manager);
-               return NULL;
+               goto fail;
        }
 
-       manager->clients = queue_new();
-       manager->supported_flags = MGMT_ADV_FLAG_LOCAL_NAME;
-
        return manager;
+
+fail:
+       manager_destroy(manager);
+       return NULL;
 }
 
 struct btd_adv_manager *btd_adv_manager_new(struct btd_adapter *adapter)