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: Host: Fix L2CAP EINPROGRESS refs #76835

Conversation

alwa-nordic
Copy link
Collaborator

Fix discrepancy in reference management between calls to bt_l2cap_chan_ops.recv when the application returns -EINPROGRESS.

There are two call sites, l2cap_chan_le_recv_sdu and l2cap_chan_le_recv, that were inconsistent.

l2cap_chan_le_recv_sdu moves the reference, and this patch updates l2cap_chan_le_recv_sdu to do the same.

This behavior is also now documented.

This bug has existed since the introduction of this feature in 3151d26.

Signed-off-by: Aleksander Wasaznik [email protected]

@alwa-nordic alwa-nordic requested a review from jori-nordic August 8, 2024 12:04
@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch from 1867fcb to 9f2dc36 Compare August 8, 2024 12:06
@alwa-nordic alwa-nordic marked this pull request as ready for review August 8, 2024 15:30
@alwa-nordic alwa-nordic added the bug The issue is a bug, or the PR is fixing a bug label Aug 8, 2024
Copy link
Collaborator

@jori-nordic jori-nordic left a comment

Choose a reason for hiding this comment

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

Please also clean-up and submit the test that found the bug.

@jhedberg
Copy link
Member

jhedberg commented Aug 9, 2024

GitHub doesn't allow me to do inline review of commit messages, so I'll do it here:

l2cap_chan_le_recv_sdu moves the reference, and this patch updates
l2cap_chan_le_recv_sdu to do the same.

The second function reference there should be l2cap_chan_le_recv, shouldn't it?

@zephyrbot zephyrbot added the platform: nRF BSIM Nordic Semiconductors, nRF BabbleSim label Aug 9, 2024
@zephyrbot zephyrbot requested a review from aescolar August 9, 2024 12:26
@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch from 2da64d7 to 9f9052e Compare August 9, 2024 12:28
@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch from 9f9052e to 6f00334 Compare August 9, 2024 12:32
@alwa-nordic
Copy link
Collaborator Author

Added test and fixed the commented-on issues.

@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch from 6f00334 to ae2630d Compare August 9, 2024 14:09
@alwa-nordic
Copy link
Collaborator Author

I'll delete the tester code, and rewrite the test. Basing it on a different test was a mistake.

@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch from 938ea3d to ae43589 Compare August 22, 2024 09:03
@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch from ae43589 to 201b1c1 Compare September 13, 2024 11:23
jori-nordic
jori-nordic previously approved these changes Sep 13, 2024
@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch 2 times, most recently from dae83b6 to 3ebe4e8 Compare October 14, 2024 12:09
Fix discrepancy in reference management between calls to
`bt_l2cap_chan_ops.recv` when the application returns `-EINPROGRESS`.

There are two call sites, `l2cap_chan_le_recv_sdu` and
`l2cap_chan_le_recv`, that were inconsistent.

`l2cap_chan_le_recv_sdu` moves the reference, and this patch updates
`l2cap_chan_le_recv` to do the same.

This behavior is also now documented.

This bug has existed since the introduction of this feature in
3151d26.

Signed-off-by: Aleksander Wasaznik <[email protected]>
For ease of development, we should log the event as an error.

Signed-off-by: Aleksander Wasaznik <[email protected]>
@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch from 3ebe4e8 to 83cebe8 Compare October 15, 2024 13:50
Thalley
Thalley previously approved these changes Oct 16, 2024
@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch 2 times, most recently from 8229fd8 to f4b8925 Compare October 21, 2024 10:51
Thalley
Thalley previously approved these changes Oct 21, 2024
theob-pro
theob-pro previously approved these changes Oct 22, 2024
@alwa-nordic alwa-nordic dismissed stale reviews from theob-pro and Thalley via e0b7903 October 24, 2024 14:52
@alwa-nordic alwa-nordic force-pushed the fix-ref-l2cap-einprogress branch 2 times, most recently from e0b7903 to 58da9bd Compare October 25, 2024 10:26
theob-pro
theob-pro previously approved these changes Oct 25, 2024
include/zephyr/bluetooth/testing.h Outdated Show resolved Hide resolved
@@ -262,13 +263,23 @@ void bt_send_one_host_num_completed_packets(uint16_t handle)
BT_ASSERT_MSG(err == 0, "Unable to send Host NCP (err %d)", err);
}

#if defined(CONFIG_BT_TESTING)
__weak void bt_testing_trace_event_acl_pool_destroy(struct net_buf *buf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a fan of public testing headers. If this is for internal testing, then I think such headers are better placed in a non-public place. Placing a testing.h makes more sense if it's a testing API that is designed to be used for users (maybe that is the intention?).

We actually recently moved the Mesh testing.h header file from the public include directory to internal.

This is needed for a test to catch a double-free.

Signed-off-by: Aleksander Wasaznik <[email protected]>
This is shorthand for random static addresses. It's similar to
`bt_addr_le_from_str`, but is a macro that results in an object literal,
making it more versatile and less verbose.

This macro only gives access to the first 255 random static addresses,
but this ought to be enough addresses for testing.

Signed-off-by: Aleksander Wasaznik <[email protected]>
The test implementation is based on a copy of the HFC multilink test.
The test verifies that the stack respects the reference counting of SDU
buffers when the L2CAP -EINPROGRESS feature is used.

Signed-off-by: Aleksander Wasaznik <[email protected]>
@Thalley Thalley requested a review from theob-pro October 26, 2024 12:17
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.

As mentioned, I will not block this PR based on the testing API, but I do have my reservations about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Host area: Bluetooth bug The issue is a bug, or the PR is fixing a bug platform: nRF BSIM Nordic Semiconductors, nRF BabbleSim
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants