-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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: host stack is broken without CONFIG_ASSERT
#73316
Comments
Would you please add steps to reproduce it? |
I believe this refers to cases like The argument is that developer time saved by catching these errors is well worth the extra bytes and cycles many times over. I agree. My opinion is that simple asserts should be on-by-default globally in Zephyr, and we maintainers should make sure assert expressions are not too expensive. Disabling asserts should be a this-train-needs-no-brakes move by those who are forced into that particular requirement and are ready to bear the cost of harder debugging. |
We depend on asserts a lot in the Bluetooth subsystem. Not enabling them will (and has) lead to confusing errors down the line, in unrelated parts of code. Fixes zephyrproject-rtos#73316 (kinda) Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Just some comments to take along:
|
I agree with you on all points. I think the issue here is: What should we recommend to our users? Asserts always on? Or asserts off in production? A default config is a pretty strong recommendation, so we should give it some consideration. I'm of the opinion that asserts enabled in production is a good thing by default. And those who have special needs can make the choice for themselves. So I wish we could turn the tide and enable asserts by default for all of Zephyr. |
Some data for @Thalley . I was expecting more asserts than that 😅 The point is, maybe we should have a null de-references: zephyr/subsys/bluetooth/host/gatt.c Lines 3469 to 3486 in 2437832
zephyr/subsys/bluetooth/host/ecc.c Lines 63 to 66 in 2437832
Broken logic: zephyr/subsys/bluetooth/host/att.c Lines 350 to 352 in 2437832
zephyr/subsys/bluetooth/host/conn.c Lines 1506 to 1511 in 2437832
ACL Control flow broken zephyr/subsys/bluetooth/host/hci_core.c Lines 574 to 579 in 2437832
Bonding that falls on the floor if there's an error zephyr/subsys/bluetooth/host/smp.c Lines 3863 to 3866 in 2437832
|
This is an actual assertion. I assert that it's impossible for it to fail. You can read 'assert' as 'theorem' here. |
Hmm, we could possibly do that. However in https://docs.zephyrproject.org/latest/contribute/guidelines.html#coding-style we state
Which in return in https://www.kernel.org/doc/html/v4.10/process/coding-style.html#macros-enums-and-rtl states
And I generally agree with that. Implicit return statements (via macros or other ways) really messes with the readers flow. So if you want to propose a macro with a return, be prepared for some pushback on that (and not just from me ;) ) |
DTS macrobatics are kosher though, definitely don't mess with people's heads, writing a driver is E-Z. In principle, I also agree that macros shouldn't mess with control flow. I really don't know what to do. |
It was going so well until you and @alwa-nordic started coming here with all your rationale and logic. It was so much easier when no-one questioned why we do what we do ;) |
To add some perspective, we tried to write an H4 HCI packet decoder in rust with @alwa-nordic and it was even more verbose than the C version 😅 . So not sure the grass is greener on that side either. |
This does not represent my opinion. /disclaimer 🙂 |
Maybe this could be solved be adding folding marks around the obvious stuff. 🤔 |
The Bluetooth host stack doesn't implement enough error handling.
A lot of parameter and state checking happens using
__ASSERT()
macros.This is a good thing, as it reduces the mental load of parsing error handling. That "error handling" usually results in a broken state somewhere else, leaks, etc..
So we need some sort of
ASSERT()
macro that is always enabled.Two solutions:
__ASSERT()
macros toBT_ASSERT()
select ASSERT
when Bluetooth is enabledNB: in the future, that macro could be redirected to allow graceful shutdown of the Bluetooth thread, if running in userspace. That way an error condition in the stack will no longer bring down the entire kernel.
The text was updated successfully, but these errors were encountered: