Skip to content

Commit 0e138cb

Browse files
alwa-nordickartben
authored andcommitted
Bluetooth: Host: K_NO_WAIT in bt_att_req_alloc() in SYS WQ
This commit prevents ATT request APIs from blocking waiting on the req_slab pool on the system work queue. The API will instead return -ENOMEM. This aligns with commit 05b16b9, which establishes that the GATT request APIs are non-blocking on the system work queue. That commit makes GATT request APIs fail with -ENOMEM when they fail to allocate a buffer for the ATT PDU on the system work queue. There is no reason to make this distinction between the two resources, and this makes the API more consistent. Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
1 parent 70a97a8 commit 0e138cb

File tree

1 file changed

+18
-4
lines changed
  • subsys/bluetooth/host

1 file changed

+18
-4
lines changed

subsys/bluetooth/host/att.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/*
44
* Copyright (c) 2015-2016 Intel Corporation
5+
* Copyright (c) 2025 Nordic Semiconductor ASA
56
*
67
* SPDX-License-Identifier: Apache-2.0
78
*/
@@ -3932,12 +3933,25 @@ static void att_chan_mtu_updated(struct bt_att_chan *updated_chan)
39323933
struct bt_att_req *bt_att_req_alloc(k_timeout_t timeout)
39333934
{
39343935
struct bt_att_req *req = NULL;
3936+
k_tid_t current_thread = k_current_get();
39353937

3936-
if (k_current_get() == att_handle_rsp_thread) {
3937-
/* No req will be fulfilled while blocking on the bt_recv thread.
3938-
* Blocking would cause deadlock.
3938+
if (current_thread == att_handle_rsp_thread ||
3939+
current_thread == k_work_queue_thread_get(&k_sys_work_q)) {
3940+
/* bt_att_req are released by the att_handle_rsp_thread.
3941+
* A blocking allocation the same thread would cause a
3942+
* deadlock.
3943+
*
3944+
* Likewise, the system work queue is used for
3945+
* tx_processor(), which is needed to send currently
3946+
* pending requests. Blocking here in a situation where
3947+
* all the request holding a bt_att_req have yet to go
3948+
* through the tx_processor() would cause a deadlock.
3949+
*
3950+
* Note the att_handle_rsp_thread might be the system
3951+
* work queue thread or the dedicated BT RX WQ thread,
3952+
* depending on kconfig.
39393953
*/
3940-
LOG_DBG("Timeout discarded. No blocking on bt_recv thread.");
3954+
LOG_DBG("Timeout discarded. No blocking on BT RX WQ or SYS WQ threads.");
39413955
timeout = K_NO_WAIT;
39423956
}
39433957

0 commit comments

Comments
 (0)