From 9148fb65d72ed8c39792cfcb8c97b184f54884ca Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 4 Jan 2023 11:40:25 +0100 Subject: [PATCH] Bluetooth: att: Fix deadlock on meta data context allocation This fixes deadlock that happened waiting for meta data in system workqueue. The meta data always get freed in the system workqueue, so if we're in the same workqueue but there are no immediate contexts available, there's no chance we'll get one by waiting. Fixes: #53455 Signed-off-by: Mariusz Skamra --- subsys/bluetooth/host/att.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 7915d942da4..65b443d04bc 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -158,6 +158,14 @@ K_FIFO_DEFINE(free_att_tx_meta_data); static struct bt_att_tx_meta_data *tx_meta_data_alloc(k_timeout_t timeout) { + /* The meta data always get freed in the system workqueue, + * so if we're in the same workqueue but there are no immediate + * contexts available, there's no chance we'll get one by waiting. + */ + if (k_current_get() == &k_sys_work_q.thread) { + return k_fifo_get(&free_att_tx_meta_data, K_NO_WAIT); + } + return k_fifo_get(&free_att_tx_meta_data, timeout); }