Skip to contentSkip to conversation

bass: Fix handling of BT_BASS_MOD_SRC

PATCH Applied Luiz Augusto von Dentz 3 participants 3 messages Oct 24, 2025 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 bass: Fix handling of BT_BASS_MOD_SRC

From: Luiz Augusto von Dentz <[email protected]>

If BT_BASS_MOD_SRC is received and the sync_state is set to BT_BASS_SYNCHRONIZED_TO_PA it doesn't necessarily mean that the device shall be removed, specially in case the assistant and broadcast source are the same device.

In order to fix this behavior this attempts to free the setups that were used for the BIS being modified, then if all setups are freed in the process proceed to disconnect the service and then check if the device is still considered connected after that, only if is not connected then remove it.

---
 profiles/audio/bass.c | 139 +++++++++++++++++++++++++-----------------
 1 file changed, 82 insertions(+), 57 deletions(-)
profiles/audio/bass.c +82 -57
index d42740ca4afb..6501d361e6ee 100644
@@ -335,6 +335,25 @@ static bool link_enabled(const void *data, const void *match_data)
 			bt_bap_stream_get_io(stream));
 }
 
+static void setup_free(void *data)
+{
+	struct bass_setup *setup = data;
+
+	DBG("setup %p", setup);
+
+	util_iov_free(setup->qos.bcast.bcode, 1);
+	util_iov_free(setup->meta, 1);
+	util_iov_free(setup->config, 1);
+	free(setup->path);
+
+	/* Clear bis index from the bis sync bitmask, if it
+	 * has been previously set.
+	 */
+	bt_bass_clear_bis_sync(setup->dg->src, setup->bis);
+
+	free(setup);
+}
+
 static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
 				uint8_t new_state, void *user_data)
 {
@@ -426,6 +445,8 @@ static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
 	case BT_BAP_STREAM_STATE_IDLE:
 		bt_bass_clear_bis_sync(dg->src, bis);
 		setup->stream = NULL;
+		queue_remove(setup->dg->setups, setup);
+		setup_free(setup);
 		break;
 	}
 }
@@ -695,23 +716,6 @@ static void bap_attached(struct bt_bap *bap, void *user_data)
 	btd_service_set_user_data(service, dg);
 }
 
-static void setup_free(void *data)
-{
-	struct bass_setup *setup = data;
-
-	DBG("setup %p", setup);
-
-	util_iov_free(setup->qos.bcast.bcode, 1);
-	util_iov_free(setup->meta, 1);
-	util_iov_free(setup->config, 1);
-	free(setup->path);
-
-	/* Clear bis index from the bis sync bitmask, if it
-	 * has been previously set.
-	 */
-	bt_bass_clear_bis_sync(setup->dg->src, setup->bis);
-}
-
 static bool match_device(const void *data, const void *match_data)
 {
 	const struct bass_data *bdata = data;
@@ -720,6 +724,41 @@ static bool match_device(const void *data, const void *match_data)
 	return bdata->device == device;
 }
 
+static void delegator_free(struct bass_delegator *dg)
+{
+	DBG("%p", dg);
+
+	if (dg->io_id)
+		g_source_remove(dg->io_id);
+
+	if (dg->io) {
+		g_io_channel_shutdown(dg->io, TRUE, NULL);
+		g_io_channel_unref(dg->io);
+	}
+
+	queue_destroy(dg->setups, setup_free);
+
+	/* Update Broadcast Receive State characteristic value and notify
+	 * peers.
+	 */
+	if (bt_bass_set_pa_sync(dg->src, BT_BASS_NOT_SYNCHRONIZED_TO_PA))
+		DBG("Failed to update Broadcast Receive State characteristic");
+
+	/* Unregister BAP stream state changed callback. */
+	bt_bap_state_unregister(dg->bap, dg->state_id);
+
+	bt_bap_bcode_cb_unregister(dg->bap, dg->bcode_id);
+
+	if (dg->timeout)
+		g_source_remove(dg->timeout);
+
+	queue_destroy(dg->bcode_reqs, free);
+
+	free(dg->bcode);
+
+	free(dg);
+}
+
 static void bap_detached(struct bt_bap *bap, void *user_data)
 {
 	struct btd_service *service;
@@ -755,37 +794,7 @@ static void bap_detached(struct bt_bap *bap, void *user_data)
 	if (!dg)
 		return;
 
-	DBG("%p", dg);
-
-	if (dg->io_id)
-		g_source_remove(dg->io_id);
-
-	if (dg->io) {
-		g_io_channel_shutdown(dg->io, TRUE, NULL);
-		g_io_channel_unref(dg->io);
-	}
-
-	queue_destroy(dg->setups, setup_free);
-
-	/* Update Broadcast Receive State characteristic value and notify
-	 * peers.
-	 */
-	if (bt_bass_set_pa_sync(dg->src, BT_BASS_NOT_SYNCHRONIZED_TO_PA))
-		DBG("Failed to update Broadcast Receive State characteristic");
-
-	/* Unregister BAP stream state changed callback. */
-	bt_bap_state_unregister(dg->bap, dg->state_id);
-
-	bt_bap_bcode_cb_unregister(dg->bap, dg->bcode_id);
-
-	if (dg->timeout)
-		g_source_remove(dg->timeout);
-
-	queue_destroy(dg->bcode_reqs, free);
-
-	free(dg->bcode);
-
-	free(dg);
+	delegator_free(dg);
 
 	btd_service_set_user_data(service, NULL);
 }
@@ -1468,22 +1477,37 @@ static int handle_mod_src_req(struct bt_bcast_src *bcast_src,
 
 	switch (sync_state) {
 	case BT_BASS_SYNCHRONIZED_TO_PA:
-		if (params->pa_sync == PA_SYNC_NO_SYNC) {
-			struct btd_adapter *adapter =
-					device_get_adapter(dg->device);
+		bass_update_bis_sync(dg, bcast_src);
 
+		/* Check if there are any setups left since it means the PA
+		 * should be no longer synchronized.
+		 */
+		if (queue_isempty(dg->setups)) {
+			/* IO is no longer needed since there are no setups */
 			g_io_channel_shutdown(dg->io, TRUE, NULL);
 			g_io_channel_unref(dg->io);
 			dg->io = NULL;
 
-			bt_bass_set_pa_sync(dg->src,
-				BT_BASS_NOT_SYNCHRONIZED_TO_PA);
+			if (!dg->service)
+				return 0;
 
-			/* Remove device of BIS source*/
-			btd_adapter_remove_device(adapter, dg->device);
-		} else {
-			bass_update_bis_sync(dg, bcast_src);
+			/* Disconnect service so BAP driver is cleanup
+			 * properly.
+			 */
+			btd_service_disconnect(dg->service);
+
+			/* If the device is no longer consider connected
+			 * it means no other service was connected so it
+			 * has no longer any use and can be safely removed.
+			 */
+			if (!btd_device_is_connected(dg->device)) {
+				struct btd_adapter *adapter;
+
+				adapter = device_get_adapter(dg->device);
+				btd_adapter_remove_device(adapter, dg->device);
+			}
 		}
+
 		break;
 	case BT_BASS_NOT_SYNCHRONIZED_TO_PA:
 		if (params->pa_sync == PA_SYNC_NO_PAST) {
@@ -1720,6 +1744,7 @@ static void bass_remove(struct btd_service *service)
 
 	bass_data_remove(data);
 }
+
 static int bass_accept(struct btd_service *service)
 {
 	struct btd_device *device = btd_service_get_device(service);
Signature · 1 line
2.51.0
#1 lore raw

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=1015549

---Test result---

Test Summary:

CheckPatch                    PENDING   0.25 seconds
GitLint                       PENDING   0.30 seconds
BuildEll                      PASS      20.03 seconds
BluezMake                     PASS      2650.83 seconds
MakeCheck                     PASS      20.68 seconds
MakeDistcheck                 PASS      184.05 seconds
CheckValgrind                 PASS      235.84 seconds
CheckSmatch                   PASS      309.91 seconds
bluezmakeextell               PASS      128.68 seconds
IncrementalBuild              PENDING   0.31 seconds
ScanBuild                     PASS      918.28 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Luiz Augusto von Dentz
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 8 lines · On Fri, 24 Oct 2025 12:25:53 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

If BT_BASS_MOD_SRC is received and the sync_state is set to BT_BASS_SYNCHRONIZED_TO_PA it doesn't necessarily mean that the device shall be removed, specially in case the assistant and broadcast source are the same device.

[...]

Here is the summary with links:
- [BlueZ,v1] bass: Fix handling of BT_BASS_MOD_SRC

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=81a995932768

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html