From 21fd387cabed65dc7716dfd74a5e4d967bbb3d09 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 20 Dec 2022 23:52:42 +0100 Subject: [PATCH] Bluetooth: Audio: Fix unicast group add/free handling of endpoints When adding or removing a stream from the group, the endpoint may or may not have been allocated depending on the state of the endpoint. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/stream.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/audio/stream.c b/subsys/bluetooth/audio/stream.c index 8f8b3081d2a..9bea7907bda 100644 --- a/subsys/bluetooth/audio/stream.c +++ b/subsys/bluetooth/audio/stream.c @@ -895,10 +895,15 @@ static void unicast_group_del_stream(struct bt_audio_unicast_group *group, __ASSERT_NO_MSG(stream != NULL); if (sys_slist_find_and_remove(&group->streams, &stream->_node)) { - unicast_group_del_iso(group, stream->ep->iso); + struct bt_audio_ep *ep = stream->ep; + + if (ep != NULL && ep->iso != NULL) { + unicast_group_del_iso(group, ep->iso); + + bt_audio_iso_unbind_ep(ep->iso, ep); + } stream->unicast_group = NULL; - bt_audio_iso_unbind_ep(stream->ep->iso, stream->ep); } } @@ -929,8 +934,14 @@ static void unicast_group_free(struct bt_audio_unicast_group *group) __ASSERT_NO_MSG(group != NULL); SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&group->streams, stream, next, _node) { + struct bt_audio_ep *ep = stream->ep; + stream->unicast_group = NULL; - bt_audio_iso_unbind_ep(stream->ep->iso, stream->ep); + + if (ep != NULL && ep->iso != NULL) { + bt_audio_iso_unbind_ep(ep->iso, ep); + } + sys_slist_remove(&group->streams, NULL, &stream->_node); }