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
Function returned 0 after an overflow, moved wrap before return. Return next_call_index = 0, since 0 is reserved.

Signed-off-by: Benjamin Lucke <[email protected]>
  • Loading branch information
Benjamin Lucke authored and LuckeTech committed Oct 30, 2023
1 parent 01aa800 commit 9a23c83
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions subsys/bluetooth/audio/tbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,18 @@ static uint8_t next_free_call_index(void)
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++;
}

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

/* For each new call, the call index should be incremented */
next_call_index++;

if (call == NULL) {
/* call == NULL is true for (next_call_index - 1)*/
return (next_call_index - 1);
}
}

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

0 comments on commit 9a23c83

Please sign in to comment.