Skip to content

Commit

Permalink
Bluetooth: TBS: Fixed return call_index 0 after overflow
Browse files Browse the repository at this point in the history
Moved wrap before return.

Signed-off-by: Benjamin Lucke <[email protected]>
  • Loading branch information
LuckeTech committed Oct 30, 2023
1 parent 01aa800 commit 5b2642b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions subsys/bluetooth/audio/tbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,22 @@ static void tbs_set_terminate_reason(struct tbs_service_inst *inst,
static uint8_t next_free_call_index(void)
{
for (int i = 0; i < CONFIG_BT_TBS_MAX_CALLS; i++) {
static uint8_t next_call_index = 1;
const struct bt_tbs_call *call = lookup_call(next_call_index);

if (call == NULL) {
return next_call_index++;
}
static uint8_t next_call_index = 0;
const struct bt_tbs_call *call;

/* For each new call, the call index should be incremented */
next_call_index++;
if (next_call_index == UINT8_MAX) {

if (next_call_index == BT_TBS_FREE_CALL_INDEX) {
/* call_index = 0 reserved for outgoing calls */
next_call_index = 1;
}

call = lookup_call(next_call_index);

if (call == NULL) {
return next_call_index;
}
}

LOG_DBG("No more free call spots");
Expand Down

0 comments on commit 5b2642b

Please sign in to comment.