Skip to content

Commit 5f89a6b

Browse files
alwa-nordichenrikbrixandersen
authored andcommitted
Bluetooth: Host: Add BT_TESTING trace event for ACL pool destroy
This is needed for a test to catch a double-free. Signed-off-by: Aleksander Wasaznik <[email protected]>
1 parent 70ad45d commit 5f89a6b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

include/zephyr/bluetooth/testing.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright (c) 2024 Nordic Semiconductor ASA
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
/** @brief Internal testing interfaces for Bluetooth
6+
* @file
7+
* @internal
8+
*
9+
* The interfaces in this file are internal and not stable.
10+
*/
11+
12+
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_TESTING_H_
13+
#define ZEPHYR_INCLUDE_BLUETOOTH_TESTING_H_
14+
15+
#include <zephyr/net_buf.h>
16+
17+
/** @brief Hook for `acl_in_pool.destroy`
18+
*
19+
* Weak-function interface. The user can simply define this
20+
* function, and it will automatically become the event
21+
* listener.
22+
*
23+
* @kconfig_dep{CONFIG_BT_TESTING}
24+
*/
25+
void bt_testing_trace_event_acl_pool_destroy(struct net_buf *buf);
26+
27+
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_TESTING_H_ */

subsys/bluetooth/host/hci_core.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <zephyr/net_buf.h>
1515
#include <zephyr/sys/atomic.h>
1616
#include <zephyr/sys/check.h>
17+
#include <zephyr/sys/util_macro.h>
1718
#include <zephyr/sys/util.h>
1819
#include <zephyr/sys/slist.h>
1920
#include <zephyr/sys/byteorder.h>
@@ -28,6 +29,7 @@
2829
#include <zephyr/bluetooth/l2cap.h>
2930
#include <zephyr/bluetooth/hci.h>
3031
#include <zephyr/bluetooth/hci_vs.h>
32+
#include <zephyr/bluetooth/testing.h>
3133
#if DT_HAS_CHOSEN(zephyr_bt_hci)
3234
#include <zephyr/drivers/bluetooth.h>
3335
#else
@@ -263,13 +265,23 @@ void bt_send_one_host_num_completed_packets(uint16_t handle)
263265
BT_ASSERT_MSG(err == 0, "Unable to send Host NCP (err %d)", err);
264266
}
265267

268+
#if defined(CONFIG_BT_TESTING)
269+
__weak void bt_testing_trace_event_acl_pool_destroy(struct net_buf *buf)
270+
{
271+
}
272+
#endif
273+
266274
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
267275
void bt_hci_host_num_completed_packets(struct net_buf *buf)
268276
{
269277
uint16_t handle = acl(buf)->handle;
270278
struct bt_conn *conn;
271279
uint8_t index = acl(buf)->index;
272280

281+
if (IS_ENABLED(CONFIG_BT_TESTING)) {
282+
bt_testing_trace_event_acl_pool_destroy(buf);
283+
}
284+
273285
net_buf_destroy(buf);
274286

275287
if (acl(buf)->host_ncp_sent) {

0 commit comments

Comments
 (0)