From 0e1c346e0dbcdf115f81e2e901403109033bb21c Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Thu, 15 Aug 2024 10:05:58 +0200 Subject: [PATCH] Bluetooth: L2CAP: Downgrade user_data API error to a warning When user_data is not zeroed-out, the API returns an error. Downgrade the API error to a warning log instead. Introducing this check (#76489) broke a few PTS tests, as user_data is not initialized by `net_buf_alloc()`. Doing so is in discussion: https://github.com/zephyrproject-rtos/zephyr/issues/77088 Signed-off-by: Jonathan Rico --- subsys/bluetooth/host/l2cap.c | 6 +++--- tests/bsim/bluetooth/host/l2cap/compile.sh | 1 - .../host/l2cap/userdata/prj_no_checks.conf | 16 ---------------- .../l2cap/userdata/src/main_l2cap_userdata.c | 15 +-------------- .../l2cap/userdata/tests_scripts/_compile.sh | 1 - .../host/l2cap/userdata/tests_scripts/l2cap.sh | 11 ----------- 6 files changed, 4 insertions(+), 46 deletions(-) delete mode 100644 tests/bsim/bluetooth/host/l2cap/userdata/prj_no_checks.conf diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index f27a31117f7203..d200bb0b91ab31 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -3135,9 +3135,9 @@ static int bt_l2cap_dyn_chan_send(struct bt_l2cap_le_chan *le_chan, struct net_b return -EINVAL; } - CHECKIF(user_data_not_empty(buf)) { - LOG_DBG("Please clear user_data first"); - return -EINVAL; + if (user_data_not_empty(buf)) { + /* There may be issues if user_data is not empty. */ + LOG_WRN("user_data is not empty"); } /* Prepend SDU length. diff --git a/tests/bsim/bluetooth/host/l2cap/compile.sh b/tests/bsim/bluetooth/host/l2cap/compile.sh index 9485c539a2acd8..7e31aab451e228 100755 --- a/tests/bsim/bluetooth/host/l2cap/compile.sh +++ b/tests/bsim/bluetooth/host/l2cap/compile.sh @@ -14,7 +14,6 @@ app=tests/bsim/bluetooth/host/l2cap/many_conns compile app=tests/bsim/bluetooth/host/l2cap/multilink_peripheral compile app=tests/bsim/bluetooth/host/l2cap/general compile app=tests/bsim/bluetooth/host/l2cap/userdata compile -app=tests/bsim/bluetooth/host/l2cap/userdata conf_file=prj_no_checks.conf compile app=tests/bsim/bluetooth/host/l2cap/stress compile app=tests/bsim/bluetooth/host/l2cap/stress conf_file=prj_nofrag.conf compile app=tests/bsim/bluetooth/host/l2cap/stress conf_file=prj_syswq.conf compile diff --git a/tests/bsim/bluetooth/host/l2cap/userdata/prj_no_checks.conf b/tests/bsim/bluetooth/host/l2cap/userdata/prj_no_checks.conf deleted file mode 100644 index 40f45991ca9a45..00000000000000 --- a/tests/bsim/bluetooth/host/l2cap/userdata/prj_no_checks.conf +++ /dev/null @@ -1,16 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_L2CAP_ECRED=y - -CONFIG_ASSERT=y -CONFIG_ARCH_POSIX_TRAP_ON_FATAL=y - -CONFIG_LOG=y -CONFIG_LOG_THREAD_ID_PREFIX=y -CONFIG_THREAD_NAME=y -# CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y - -CONFIG_NO_RUNTIME_CHECKS=y diff --git a/tests/bsim/bluetooth/host/l2cap/userdata/src/main_l2cap_userdata.c b/tests/bsim/bluetooth/host/l2cap/userdata/src/main_l2cap_userdata.c index d11e56c65dfd4b..d7f42d0d28eefc 100644 --- a/tests/bsim/bluetooth/host/l2cap/userdata/src/main_l2cap_userdata.c +++ b/tests/bsim/bluetooth/host/l2cap/userdata/src/main_l2cap_userdata.c @@ -258,20 +258,7 @@ static void test_central_main(void) */ err = bt_l2cap_chan_send(&channel.chan, buf); - if (has_checks) { - /* The stack is supposed to reject `buf` if it has non-null - * user_data. - */ - if (err == -EINVAL) { - PASS("(Enabled-checks) Test passed\n"); - return; - } - - FAIL("Expected EINVAL (%d) got %d\n", -EINVAL, err); - } - - /* We have bypassed runtime checks of user_data. L2CAP will take our - * `buf` with non-null user_data. We verify that: + /* L2CAP will take our `buf` with non-null user_data. We verify that: * - it is cleared * - we don't segfault later (e.g. in `tx_notify`) */ diff --git a/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/_compile.sh b/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/_compile.sh index 7ed5e4306531dc..80030a894f2b38 100755 --- a/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/_compile.sh @@ -8,6 +8,5 @@ INCR_BUILD=1 source ${ZEPHYR_BASE}/tests/bsim/compile.source app="$(guess_test_relpath)" compile -app="$(guess_test_relpath)" conf_file=prj_no_checks.conf compile wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh b/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh index 1374442f442abe..e5bcdd078c0d92 100755 --- a/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh +++ b/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh @@ -20,14 +20,3 @@ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=5e6 $@ wait_for_background_jobs - -Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_l2cap_userdata_prj_no_checks_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_host_l2cap_userdata_prj_no_checks_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=5e6 $@ - -wait_for_background_jobs