avdtp: Fix removing all remote SEPs when loading from cache
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 11 Mar 2021 15:36:07 +0000 (07:36 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:34 +0000 (19:08 +0530)
If avdtp_discover is called after cache has been loaded it end up
removing all remote SEPs as they have not been discovered yet.

Fixes: https://github.com/bluez/bluez/issues/102
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/audio/avdtp.c

index eab333d..58f5e5a 100644 (file)
@@ -3906,10 +3906,18 @@ int avdtp_discover(struct avdtp *session, avdtp_discover_cb_t cb,
        session->discover = g_new0(struct discover_callback, 1);
 
        if (session->seps) {
-               session->discover->cb = cb;
-               session->discover->user_data = user_data;
-               session->discover->id = g_idle_add(process_discover, session);
-               return 0;
+               struct avdtp_remote_sep *sep = session->seps->data;
+
+               /* Check that SEP have been discovered as it may be loaded from
+                * cache.
+                */
+               if (sep->discovered) {
+                       session->discover->cb = cb;
+                       session->discover->user_data = user_data;
+                       session->discover->id = g_idle_add(process_discover,
+                                                               session);
+                       return 0;
+               }
        }
 
        err = send_request(session, FALSE, NULL, AVDTP_DISCOVER, NULL, 0);