From a68f78526db1e8003781ebaf2ea8724e3f86842e Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 7 Dec 2022 16:01:06 +0100 Subject: [PATCH] Bluetooth: audio: tbs_client: Fix misleading error log This fixes error log that has been shown if number of calls in the list was equal to CONFIG_BT_TBS_CLIENT_MAX_CALLS. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/tbs_client.c | 38 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/subsys/bluetooth/audio/tbs_client.c b/subsys/bluetooth/audio/tbs_client.c index e3d38279aa9..9512025f337 100644 --- a/subsys/bluetooth/audio/tbs_client.c +++ b/subsys/bluetooth/audio/tbs_client.c @@ -200,8 +200,14 @@ static void bearer_list_current_calls(struct bt_conn *conn, const struct bt_tbs_ int err; while (buf->len) { - struct bt_tbs_client_call *call = &calls[cnt]; + struct bt_tbs_client_call *call; + if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { + LOG_WRN("Could not parse all calls due to memory restrictions"); + break; + } + + call = &calls[cnt]; call->remote_uri = remote_uris[cnt]; err = net_buf_pull_call(buf, call); @@ -214,10 +220,6 @@ static void bearer_list_current_calls(struct bt_conn *conn, const struct bt_tbs_ } cnt++; - if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { - LOG_WRN("Could not parse all calls due to memory restrictions"); - break; - } } if (tbs_client_cbs != NULL && tbs_client_cbs->current_calls != NULL) { @@ -421,9 +423,16 @@ static void call_state_notify_handler(struct bt_conn *conn, /* TODO: If length == MTU, do long read for all call states */ while (buf.len) { - struct bt_tbs_client_call_state *call_state = &call_states[cnt]; + struct bt_tbs_client_call_state *call_state; int err; + if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { + LOG_WRN("Could not parse all calls due to memory restrictions"); + break; + } + + call_state = &call_states[cnt]; + err = net_buf_pull_call_state(&buf, call_state); if (err != 0) { LOG_DBG("Invalid current call notification: %d", err); @@ -431,10 +440,6 @@ static void call_state_notify_handler(struct bt_conn *conn, } cnt++; - if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { - LOG_WRN("Could not parse all calls due to memory restrictions"); - break; - } } if (tbs_client_cbs != NULL && tbs_client_cbs->call_state != NULL) { @@ -1051,7 +1056,14 @@ static uint8_t read_call_state_cb(struct bt_conn *conn, uint8_t err, /* Finished reading, start parsing */ while (inst->net_buf.len != 0) { - struct bt_tbs_client_call_state *call_state = &call_states[cnt]; + struct bt_tbs_client_call_state *call_state; + + if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { + LOG_WRN("Could not parse all calls due to memory restrictions"); + break; + } + + call_state = &call_states[cnt]; tbs_err = net_buf_pull_call_state(&inst->net_buf, call_state); if (tbs_err != 0) { @@ -1060,10 +1072,6 @@ static uint8_t read_call_state_cb(struct bt_conn *conn, uint8_t err, } cnt++; - if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { - LOG_WRN("Could not parse all calls due to memory restrictions"); - break; - } } (void)memset(params, 0, sizeof(*params));