From 0f5f748580cb8a152efb9efcba72520154c2c6f5 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 21 Feb 2025 09:32:18 +0200 Subject: [PATCH] Bluetoth: Host: Fix buffer allocation warnings in system workqueue The buffer allocation in conn.c will trigger warnings if we try to use anything else than K_NO_WAIT for the timeout when called from within the system workqueue. The calls in l2cap.c and att.c which may pass non-zero timeouts already have proper handling for failed allocations, so make sure we use K_NO_WAIT to avoid unnecessary warnings from conn.c. Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/att.c | 6 +++++- subsys/bluetooth/host/l2cap.c | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 1ae38457255ba..5b3364ace55b7 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -730,7 +730,11 @@ static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t timeout = BT_ATT_TIMEOUT; break; default: - timeout = K_FOREVER; + if (k_current_get() == k_work_queue_thread_get(&k_sys_work_q)) { + timeout = K_NO_WAIT; + } else { + timeout = K_FOREVER; + } } /* This will reserve headspace for lower layers */ diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 03b68592d5c0f..acc01a1950faa 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -674,6 +674,11 @@ struct net_buf *bt_l2cap_create_pdu_timeout(struct net_buf_pool *pool, size_t reserve, k_timeout_t timeout) { + if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT) && + k_current_get() == k_work_queue_thread_get(&k_sys_work_q)) { + timeout = K_NO_WAIT; + } + return bt_conn_create_pdu_timeout(pool, sizeof(struct bt_l2cap_hdr) + reserve, timeout);