Skip to contentSkip to conversation

shared/bap: Protect bap_stream_notify_connecting

PATCH Applied Luiz Augusto von Dentz 1 participant 1 message Jun 29 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v3 5/5 shared/bap: Protect bap_stream_notify_connecting

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

bap_stream_notify_connecting may encounter callbacks that remove itself while traversing the state_cbs, so this attempts to prevent to cause a crash by prefetching the next entry.

---
 src/shared/bap.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
src/shared/bap.c +6 -2
index 7bcf28bcefe4..1f61227f82a7 100644
@@ -3036,10 +3036,14 @@ static void bap_stream_notify_connecting(struct bt_bap_stream *stream,
 {
 	const struct queue_entry *entry;
 
-	for (entry = queue_get_entries(stream->bap->state_cbs); entry;
-						entry = entry->next) {
+	for (entry = queue_get_entries(stream->bap->state_cbs); entry;) {
 		struct bt_bap_state *state = entry->data;
 
+		/* Prefetch next entry since the callback may remove the current
+		 * entry.
+		 */
+		entry = entry->next;
+
 		if (state->connecting)
 			state->connecting(stream, connecting, fd, state->data);
 	}
Signature · 1 line
2.54.0