Bluetooth: Audio: Fix issue with invalid bt_conn_ref in ASCS

In ascs.c we had a case where we assigned stream->conn
without taking the ref.

In bt_audio_stream_attach we did not check if stream->conn
was NULL before taking a reference, causing multiple calls
to ase_config to take multiple references.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2023-01-16 11:32:47 +01:00 committed by Carles Cufí
commit b43f1351ed
2 changed files with 6 additions and 2 deletions

View file

@ -1012,7 +1012,9 @@ static void ase_stream_add(struct bt_ascs *ascs, struct bt_ascs_ase *ase,
{
LOG_DBG("ase %p stream %p", ase, stream);
ase->ep.stream = stream;
stream->conn = ascs->conn;
if (stream->conn == NULL) {
stream->conn = bt_conn_ref(ascs->conn);
}
stream->ep = &ase->ep;
}

View file

@ -81,7 +81,9 @@ void bt_audio_stream_attach(struct bt_conn *conn,
if (conn != NULL) {
__ASSERT(stream->conn == NULL || stream->conn == conn,
"stream->conn %p already attached", stream->conn);
stream->conn = bt_conn_ref(conn);
if (stream->conn == NULL) {
stream->conn = bt_conn_ref(conn);
}
}
stream->codec = codec;
stream->ep = ep;