Skip to content

Commit 4c05840

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: Audio: Fix issue with deleting unicast groups
There was a bug in bt_audio_iso_unbind_ep that caused an assert, missing unbinding on stream released callback and missing state check in bt_audio_unicast_group_delete Signed-off-by: Emil Gydesen <[email protected]>
1 parent 346836b commit 4c05840

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

subsys/bluetooth/audio/audio_iso.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ void bt_audio_iso_unbind_ep(struct bt_audio_iso *iso, struct bt_audio_ep *ep)
184184

185185
__ASSERT_NO_MSG(ep != NULL);
186186
__ASSERT_NO_MSG(iso != NULL);
187-
__ASSERT(ep->iso == iso, "ep %p not bound with iso", iso, ep);
187+
__ASSERT(ep->iso == iso, "ep %p not bound with iso %p, was bound to %p",
188+
ep, iso, ep->iso);
188189
__ASSERT(ep->dir == BT_AUDIO_DIR_SINK || ep->dir == BT_AUDIO_DIR_SOURCE,
189190
"Invalid dir: %u", ep->dir);
190191

@@ -194,12 +195,12 @@ void bt_audio_iso_unbind_ep(struct bt_audio_iso *iso, struct bt_audio_ep *ep)
194195
bt_audio_ep_is_unicast_client(ep)) {
195196
/* For the unicast client, the direction and tx/rx is reversed */
196197
if (ep->dir == BT_AUDIO_DIR_SOURCE) {
197-
__ASSERT(iso->rx.ep == NULL,
198-
"iso %p not bound with ep %p", iso, iso->rx.ep);
198+
__ASSERT(iso->rx.ep == ep,
199+
"iso %p not bound with ep %p", iso, ep);
199200
iso->rx.ep = NULL;
200201
} else {
201-
__ASSERT(iso->tx.ep == NULL,
202-
"iso %p not bound with ep %p", iso, iso->tx.ep);
202+
__ASSERT(iso->tx.ep == ep,
203+
"iso %p not bound with ep %p", iso, ep);
203204
iso->tx.ep = NULL;
204205
}
205206
} else {

subsys/bluetooth/audio/stream.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ void bt_audio_stream_reset(struct bt_audio_stream *stream)
324324
return;
325325
}
326326

327+
if (stream->ep != NULL && stream->ep->iso != NULL) {
328+
bt_audio_iso_unbind_ep(stream->ep->iso, stream->ep);
329+
}
330+
327331
bt_audio_stream_detach(stream);
328332
}
329333

@@ -1139,11 +1143,23 @@ int bt_audio_unicast_group_add_streams(struct bt_audio_unicast_group *unicast_gr
11391143

11401144
int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group)
11411145
{
1146+
struct bt_audio_stream *stream;
1147+
11421148
CHECKIF(unicast_group == NULL) {
11431149
LOG_DBG("unicast_group is NULL");
11441150
return -EINVAL;
11451151
}
11461152

1153+
SYS_SLIST_FOR_EACH_CONTAINER(&unicast_group->streams, stream, _node) {
1154+
/* If a stream has an endpoint, it is not ready to be removed
1155+
* from a group, as it is not in an idle state
1156+
*/
1157+
if (stream->ep != NULL) {
1158+
LOG_DBG("stream %p is not released", stream);
1159+
return -EINVAL;
1160+
}
1161+
}
1162+
11471163
if (unicast_group->cig != NULL) {
11481164
const int err = bt_audio_cig_terminate(unicast_group);
11491165

0 commit comments

Comments
 (0)