Skip to content

Commit 5a4fdfb

Browse files
jori-nordiccarlescufi
authored andcommitted
Bluetooth: hci_common: Add assert on buf allocation
`net_buf_alloc(K_FOREVER)` can now return NULL if running in the system workqueue. `bt_hci_evt_create()` is called in that context in a few cases. Since we can't really do anything about it, add a (default-on) assert. This should ideally never fail. I saw it fail because of a leak in the ACL buffer pool, which is also shared with events when host flow control is not enabled. In that particular case, the host is rendered non-functional, so trying to recover using error handling is futile. Signed-off-by: Jonathan Rico <[email protected]>
1 parent e489ec2 commit 5a4fdfb

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

subsys/bluetooth/host/hci_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdint.h>
88
#include <zephyr/sys/byteorder.h>
99
#include <zephyr/drivers/bluetooth/hci_driver.h>
10+
#include "common/assert.h"
1011

1112
struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len)
1213
{
@@ -15,6 +16,8 @@ struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len)
1516

1617
buf = bt_buf_get_evt(evt, false, K_FOREVER);
1718

19+
BT_ASSERT(buf);
20+
1821
hdr = net_buf_add(buf, sizeof(*hdr));
1922
hdr->evt = evt;
2023
hdr->len = len;

0 commit comments

Comments
 (0)