-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Bluetooth: TBS: Fixed return call_index 0 after overflow #64545
Conversation
9a23c83
to
5ebf829
Compare
subsys/bluetooth/audio/tbs.c
Outdated
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); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right.
There was a problem hiding this comment.
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
3a5cf6c
to
be03570
Compare
subsys/bluetooth/audio/tbs.c
Outdated
} | ||
|
||
const struct bt_tbs_call *call = lookup_call(next_call_index); |
There was a problem hiding this comment.
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
229dc8d
to
42fb1ae
Compare
There was a problem hiding this 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.
The commit message should also be elaborated a bit more and should state what is being fixed and why |
5b2642b
to
42be018
Compare
There was a problem hiding this 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
42be018
to
18ab507
Compare
Fixed range of call_index 1 to 255, since 0 is reserved for outgoing calls. Signed-off-by: Benjamin Lucke <[email protected]>
9eb84c8
to
429756e
Compare
Function returned 0 after an overflow, moved wrap before return.
Return next_call_index = 0, since 0 is reserved.