linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] a2dp: Invalidate cache if SetConfiguration fails
@ 2021-08-03 21:41 Luiz Augusto von Dentz
  2021-08-03 22:36 ` bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2021-08-03 21:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If SetConfiguration fails with Unsupported Configuration it might
indicate that either the capabilities stored are incorrect or the seid
may have changed, so this attempt to invalidate the remote seps loaded
from cache when that happens so the next time there is an attempt to
discover this will force Get(All)Capabilities to be called and cause
the cache to be updated.
---
 profiles/audio/a2dp.c  | 56 ++++++++++++++++++++++++++++++++----------
 profiles/audio/avdtp.c | 11 +++++++++
 profiles/audio/avdtp.h |  2 ++
 3 files changed, 56 insertions(+), 13 deletions(-)

diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 86bc02994..68af9da1a 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -127,6 +127,7 @@ struct a2dp_remote_sep {
 	struct a2dp_channel *chan;
 	char *path;
 	struct avdtp_remote_sep *sep;
+	bool from_cache;
 };
 
 struct a2dp_last_used {
@@ -773,6 +774,32 @@ done:
 	setup_unref(setup);
 }
 
+static bool match_remote_sep(const void *data, const void *user_data)
+{
+	const struct a2dp_remote_sep *sep = data;
+	const struct avdtp_remote_sep *rsep = user_data;
+
+	return sep->sep == rsep;
+}
+
+static void invalidate_remote_cache(struct a2dp_setup *setup,
+						struct avdtp_error *err)
+{
+	struct a2dp_remote_sep *rsep;
+
+	if (err->category != AVDTP_ERRNO ||
+			err->err.error_code != AVDTP_UNSUPPORTED_CONFIGURATION)
+		return;
+
+	/* Attempt to unregister Remove SEP if configuration
+	 * fails with Unsupported Configuration and it was
+	 * loaded from cache.
+	 */
+	rsep = queue_find(setup->chan->seps, match_remote_sep, setup->rsep);
+	if (rsep && rsep->from_cache)
+		avdtp_unregister_remote_sep(setup->session, rsep->sep);
+}
+
 static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
 				struct avdtp_stream *stream,
 				struct avdtp_error *err, void *user_data)
@@ -794,10 +821,12 @@ static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
 		if (setup) {
 			setup_ref(setup);
 			setup->err = err;
+			invalidate_remote_cache(setup, err);
 			finalize_config(setup);
 			setup->err = NULL;
 			setup_unref(setup);
 		}
+
 		return;
 	}
 
@@ -874,14 +903,6 @@ static void getconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
 		DBG("Source %p: Set_Configuration_Cfm", sep);
 }
 
-static bool match_remote_sep(const void *data, const void *user_data)
-{
-	const struct a2dp_remote_sep *sep = data;
-	const struct avdtp_remote_sep *rsep = user_data;
-
-	return sep->sep == rsep;
-}
-
 static void store_last_used(struct a2dp_channel *chan, uint8_t lseid,
 							uint8_t rseid)
 {
@@ -1941,7 +1962,7 @@ static void remote_sep_destroy(void *user_data)
 		remove_remote_sep(sep);
 }
 
-static void register_remote_sep(void *data, void *user_data)
+static struct a2dp_remote_sep *register_remote_sep(void *data, void *user_data)
 {
 	struct avdtp_remote_sep *rsep = data;
 	struct a2dp_channel *chan = user_data;
@@ -1949,7 +1970,7 @@ static void register_remote_sep(void *data, void *user_data)
 
 	sep = queue_find(chan->seps, match_remote_sep, rsep);
 	if (sep)
-		return;
+		return sep;
 
 	sep = new0(struct a2dp_remote_sep, 1);
 	sep->chan = chan;
@@ -1972,7 +1993,7 @@ static void register_remote_sep(void *data, void *user_data)
 		error("Could not register remote sep %s", sep->path);
 		free(sep->path);
 		free(sep);
-		return;
+		return NULL;
 	}
 
 	DBG("Found remote SEP: %s", sep->path);
@@ -1981,6 +2002,8 @@ static void register_remote_sep(void *data, void *user_data)
 
 done:
 	queue_push_tail(chan->seps, sep);
+
+	return sep;
 }
 
 static bool match_seid(const void *data, const void *user_data)
@@ -2080,7 +2103,9 @@ static void load_remote_sep(struct a2dp_channel *chan, GKeyFile *key_file,
 			continue;
 		}
 
-		register_remote_sep(rsep, chan);
+		sep = register_remote_sep(rsep, chan);
+		if (sep)
+			sep->from_cache = true;
 	}
 
 	value = g_key_file_get_string(key_file, "Endpoints", "LastUsed", NULL);
@@ -2778,6 +2803,11 @@ static void store_remote_seps(struct a2dp_channel *chan)
 	g_key_file_free(key_file);
 }
 
+static void foreach_register_remote_sep(void *data, void *user_data)
+{
+	register_remote_sep(data, user_data);
+}
+
 static void discover_cb(struct avdtp *session, GSList *seps,
 				struct avdtp_error *err, void *user_data)
 {
@@ -2791,7 +2821,7 @@ static void discover_cb(struct avdtp *session, GSList *seps,
 		setup->err = err;
 
 	if (!err) {
-		g_slist_foreach(seps, register_remote_sep, setup->chan);
+		g_slist_foreach(seps, foreach_register_remote_sep, setup->chan);
 
 		/* Only store version has been initialized as features like
 		 * Delay Reporting may not be queried if the version in
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index 5d13104c1..38043d757 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -3364,6 +3364,17 @@ struct avdtp_remote_sep *avdtp_register_remote_sep(struct avdtp *session,
 	return sep;
 }
 
+int avdtp_unregister_remote_sep(struct avdtp *session,
+						struct avdtp_remote_sep *rsep)
+{
+	if (!session || !rsep)
+		return -EINVAL;
+
+	session->seps = g_slist_remove(session->seps, rsep);
+
+	sep_free(rsep);
+}
+
 void avdtp_remote_sep_set_destroy(struct avdtp_remote_sep *sep, void *user_data,
 					avdtp_remote_sep_destroy_t destroy)
 {
diff --git a/profiles/audio/avdtp.h b/profiles/audio/avdtp.h
index b29d0621a..b02534cd5 100644
--- a/profiles/audio/avdtp.h
+++ b/profiles/audio/avdtp.h
@@ -215,6 +215,8 @@ struct avdtp_remote_sep *avdtp_register_remote_sep(struct avdtp *session,
 							uint8_t type,
 							GSList *caps,
 							bool delay_reporting);
+int avdtp_unregister_remote_sep(struct avdtp *session,
+						struct avdtp_remote_sep *rsep);
 
 typedef void (*avdtp_remote_sep_destroy_t)(void *user_data);
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [RFC] a2dp: Invalidate cache if SetConfiguration fails
  2021-08-03 21:41 [RFC] a2dp: Invalidate cache if SetConfiguration fails Luiz Augusto von Dentz
@ 2021-08-03 22:36 ` bluez.test.bot
  0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2021-08-03 22:36 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 3018 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=525905

---Test result---

Test Summary:
CheckPatch                    PASS      0.53 seconds
GitLint                       PASS      0.13 seconds
Prep - Setup ELL              PASS      50.77 seconds
Build - Prep                  PASS      0.14 seconds
Build - Configure             PASS      8.76 seconds
Build - Make                  FAIL      168.83 seconds
Make Check                    FAIL      1.49 seconds
Make Distcheck                PASS      258.85 seconds
Build w/ext ELL - Configure   PASS      8.73 seconds
Build w/ext ELL - Make        FAIL      153.68 seconds

Details
##############################
Test: CheckPatch - PASS
Desc: Run checkpatch.pl script with rule in .checkpatch.conf

##############################
Test: GitLint - PASS
Desc: Run gitlint with rule in .gitlint

##############################
Test: Prep - Setup ELL - PASS
Desc: Clone, build, and install ELL

##############################
Test: Build - Prep - PASS
Desc: Prepare environment for build

##############################
Test: Build - Configure - PASS
Desc: Configure the BlueZ source tree

##############################
Test: Build - Make - FAIL
Desc: Build the BlueZ source tree
Output:
profiles/audio/avdtp.c: In function ‘avdtp_unregister_remote_sep’:
profiles/audio/avdtp.c:3376:1: error: control reaches end of non-void function [-Werror=return-type]
 3376 | }
      | ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:8553: profiles/audio/bluetoothd-avdtp.o] Error 1
make: *** [Makefile:4142: all] Error 2


##############################
Test: Make Check - FAIL
Desc: Run 'make check'
Output:
profiles/audio/avdtp.c: In function ‘avdtp_unregister_remote_sep’:
profiles/audio/avdtp.c:3376:1: error: control reaches end of non-void function [-Werror=return-type]
 3376 | }
      | ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:8553: profiles/audio/bluetoothd-avdtp.o] Error 1
make: *** [Makefile:10414: check] Error 2


##############################
Test: Make Distcheck - PASS
Desc: Run distcheck to check the distribution

##############################
Test: Build w/ext ELL - Configure - PASS
Desc: Configure BlueZ source with '--enable-external-ell' configuration

##############################
Test: Build w/ext ELL - Make - FAIL
Desc: Build BlueZ source with '--enable-external-ell' configuration
Output:
profiles/audio/avdtp.c: In function ‘avdtp_unregister_remote_sep’:
profiles/audio/avdtp.c:3376:1: error: control reaches end of non-void function [-Werror=return-type]
 3376 | }
      | ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:8553: profiles/audio/bluetoothd-avdtp.o] Error 1
make: *** [Makefile:4142: all] Error 2




---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-03 22:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 21:41 [RFC] a2dp: Invalidate cache if SetConfiguration fails Luiz Augusto von Dentz
2021-08-03 22:36 ` bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).