From dcd1e6aa35915a5f3b1172ccaa99cf972950967e Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 18 Jul 2025 14:16:13 +0200 Subject: [PATCH] Bluetooth: ISO: Cleanup BIG before stopped callback Modify the big_disconnect function to do cleanup_big before calling the `stopped` callback. This will allow the ISO channels, as well as the BIG itself, to be reused for other purposes directly in the stopped callback, without having to offload such actions to a separate thread. Signed-off-by: Emil Gydesen --- subsys/bluetooth/host/iso.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 5f535131634d7..5c5914f507502 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -2719,6 +2719,11 @@ static void big_disconnect(struct bt_iso_big *big, uint8_t reason) bt_iso_chan_disconnected(bis, reason); } + /* Cleanup the BIG before calling the `stopped` so that the `big` pointer and the ISO + * channels in the `big` can be reused in the callback + */ + cleanup_big(big); + if (!sys_slist_is_empty(&iso_big_cbs)) { struct bt_iso_big_cb *listener; @@ -3135,7 +3140,6 @@ void hci_le_big_complete(struct net_buf *buf) big = big_lookup_flag(BT_BIG_PENDING); if (big) { big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED); - cleanup_big(big); } return; @@ -3153,7 +3157,6 @@ void hci_le_big_complete(struct net_buf *buf) big->num_bis); } big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED); - cleanup_big(big); return; } @@ -3193,7 +3196,6 @@ void hci_le_big_terminate(struct net_buf *buf) LOG_DBG("BIG[%u] %p terminated", big->handle, big); big_disconnect(big, evt->reason); - cleanup_big(big); } #endif /* CONFIG_BT_ISO_BROADCASTER */ @@ -3280,7 +3282,6 @@ int bt_iso_big_terminate(struct bt_iso_big *big) if (!err) { big_disconnect(big, BT_HCI_ERR_LOCALHOST_TERM_CONN); - cleanup_big(big); } } else { err = -EINVAL; @@ -3325,7 +3326,6 @@ void hci_le_big_sync_established(struct net_buf *buf) big = big_lookup_flag(BT_BIG_SYNCING); if (big) { big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED); - cleanup_big(big); } return; @@ -3343,7 +3343,6 @@ void hci_le_big_sync_established(struct net_buf *buf) big->num_bis); } big_disconnect(big, evt->status ? evt->status : BT_HCI_ERR_UNSPECIFIED); - cleanup_big(big); return; } @@ -3383,7 +3382,6 @@ void hci_le_big_sync_lost(struct net_buf *buf) LOG_DBG("BIG[%u] %p sync lost", big->handle, big); big_disconnect(big, evt->reason); - cleanup_big(big); } static int hci_le_big_create_sync(const struct bt_le_per_adv_sync *sync, struct bt_iso_big *big, @@ -3575,7 +3573,6 @@ void bt_iso_reset(void) struct bt_iso_big *big = &bigs[i]; big_disconnect(big, BT_HCI_ERR_UNSPECIFIED); - cleanup_big(big); } #endif /* CONFIG_BT_ISO_BROADCAST */ }