Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: TBS: Fixed return call_index 0 after overflow #64545

Merged

Conversation

LuckeTech
Copy link
Contributor

Function returned 0 after an overflow, moved wrap before return.
Return next_call_index = 0, since 0 is reserved.

Comment on lines 313 to 324
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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either I'm missing something, or this won't return 255

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now. @MariuszSkamra

@LuckeTech LuckeTech force-pushed the fix_tbs_call_index_overflow branch 3 times, most recently from 3a5cf6c to be03570 Compare October 30, 2023 11:36
}

const struct bt_tbs_call *call = lookup_call(next_call_index);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not declare the variables in the middle of the scope

@LuckeTech LuckeTech force-pushed the fix_tbs_call_index_overflow branch 2 times, most recently from 229dc8d to 42fb1ae Compare October 30, 2023 12:32
Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch on the bug, although it is pretty mood since CONFIG_BT_TBS_MAX_CALLS can maximum be 16 at this point:

config BT_TBS_MAX_CALLS
	int "Telephone Bearer Service Maximum Number Of Calls Supported"
	default 3
	range 1 16
	help
	  Sets the maximum number of calls the service supports per bearer.

So next_call_index could never be larger than 17.

In any case, we might as well fix it.

subsys/bluetooth/audio/tbs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/tbs.c Outdated Show resolved Hide resolved
@Thalley
Copy link
Collaborator

Thalley commented Oct 30, 2023

The commit message should also be elaborated a bit more and should state what is being fixed and why

@LuckeTech LuckeTech force-pushed the fix_tbs_call_index_overflow branch 2 times, most recently from 5b2642b to 42be018 Compare October 30, 2023 12:46
Thalley
Thalley previously approved these changes Oct 30, 2023
Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution :) Minor comment, but it is OK as is

subsys/bluetooth/audio/tbs.c Outdated Show resolved Hide resolved
Fixed range of call_index 1 to 255, since 0 is reserved for outgoing calls.

Signed-off-by: Benjamin Lucke <[email protected]>
@LuckeTech LuckeTech force-pushed the fix_tbs_call_index_overflow branch from 9eb84c8 to 429756e Compare October 31, 2023 06:20
@carlescufi carlescufi merged commit 1b34884 into zephyrproject-rtos:main Nov 3, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants