Skip to content

Commit 4c2bd49

Browse files
committed
Bluetooth: Host: Don't call user callback from TX thread
We invoked user callbacks from a net_buf_unref() inside the HCI driver. This is not OK now that tx_processor is a non-blocking task on bt_taskq. Instead defer the net_buf destruction to the system workqueue. This was detected because the following test was failing: tests/bsim/bluetooth/ll/throughput/tests_scripts/gatt_write.sh Signed-off-by: Aleksander Wasaznik <[email protected]>
1 parent 47bcc44 commit 4c2bd49

File tree

1 file changed

+16
-1
lines changed
  • subsys/bluetooth/host

1 file changed

+16
-1
lines changed

subsys/bluetooth/host/att.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,13 @@ const char *bt_att_err_to_str(uint8_t att_err)
248248
}
249249
#endif /* CONFIG_BT_ATT_ERR_TO_STR */
250250

251-
static void att_tx_destroy(struct net_buf *buf)
251+
static void att_tx_destroy_work_handler(struct k_work *work);
252+
static K_WORK_DEFINE(att_tx_destroy_work, att_tx_destroy_work_handler);
253+
static sys_slist_t tx_destroy_queue;
254+
255+
static void att_tx_destroy_work_handler(struct k_work *work)
252256
{
257+
struct net_buf *buf = net_buf_slist_get(&tx_destroy_queue);
253258
struct bt_att_tx_meta_data *p_meta = att_get_tx_meta_data(buf);
254259
struct bt_att_tx_meta_data meta;
255260

@@ -278,6 +283,16 @@ static void att_tx_destroy(struct net_buf *buf)
278283
if (meta.opcode != 0) {
279284
att_on_sent_cb(&meta);
280285
}
286+
287+
if (!sys_slist_is_empty(&tx_destroy_queue)) {
288+
k_work_submit(&att_tx_destroy_work);
289+
}
290+
}
291+
292+
static void att_tx_destroy(struct net_buf *buf)
293+
{
294+
net_buf_slist_put(&tx_destroy_queue, buf);
295+
k_work_submit(&att_tx_destroy_work);
281296
}
282297

283298
NET_BUF_POOL_DEFINE(att_pool, CONFIG_BT_ATT_TX_COUNT,

0 commit comments

Comments
 (0)