OSDN Git Service

core: Fix calling profile .connect multiple times
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 8 Feb 2013 09:51:28 +0000 (11:51 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Fri, 15 Feb 2013 10:51:45 +0000 (12:51 +0200)
Sometimes profiles may complete the connection in different order
than expected so the code has to check if it was actually the
current pending profile to proceed to the next.

src/device.c

index 686dbfb..4320234 100644 (file)
@@ -1075,8 +1075,14 @@ static int connect_next(struct btd_device *dev)
 void device_profile_connected(struct btd_device *dev,
                                        struct btd_profile *profile, int err)
 {
+       struct btd_profile *pending;
+
        DBG("%s %s (%d)", profile->name, strerror(-err), -err);
 
+       if (dev->pending == NULL)
+               return;
+
+       pending = dev->pending->data;
        dev->pending = g_slist_remove(dev->pending, profile);
 
        if (!err)
@@ -1084,6 +1090,13 @@ void device_profile_connected(struct btd_device *dev,
                                g_slist_append(dev->connected_profiles,
                                                                profile);
 
+       /* Only continue connecting the next profile if it matches the first
+        * pending, otherwise it will trigger another connect to the same
+        * profile
+        */
+       if (profile != pending)
+               return;
+
        if (connect_next(dev) == 0)
                return;