diff mbox series

[BlueZ,3/5] shared/bap: Cleanup requests on detach

Message ID 20230301013842.718438-3-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit 36c234625bda881bc9d5bd99305706b86d117716
Headers show
Series [BlueZ,1/5] device: Don't attempt to connect LE if ATT is already connected | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Luiz Augusto von Dentz March 1, 2023, 1:38 a.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If session is being detached any ongoing/queue request shall be
cancelled as well otherwise when the session is attach again they would
be invalid.
---
 src/shared/bap.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/src/shared/bap.c b/src/shared/bap.c
index f16ba1832aaa..c63612f0da47 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -3820,6 +3820,13 @@  static void stream_foreach_detach(void *data, void *user_data)
 	stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
 }
 
+static void bap_req_detach(void *data)
+{
+	struct bt_bap_req *req = data;
+
+	bap_req_complete(req, NULL);
+}
+
 void bt_bap_detach(struct bt_bap *bap)
 {
 	DBG(bap, "%p", bap);
@@ -3827,6 +3834,15 @@  void bt_bap_detach(struct bt_bap *bap)
 	if (!queue_remove(sessions, bap))
 		return;
 
+	/* Cancel ongoing request */
+	if (bap->req) {
+		bap_req_detach(bap->req);
+		bap->req = NULL;
+	}
+
+	/* Cancel queued requests */
+	queue_remove_all(bap->reqs, NULL, NULL, bap_req_detach);
+
 	bt_gatt_client_unref(bap->client);
 	bap->client = NULL;