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 <jonathan.rico@nordicsemi.no>
This commit is contained in:
Jonathan Rico 2024-08-08 08:34:52 +02:00 committed by Carles Cufí
parent e489ec2b95
commit 5a4fdfbf3e

View file

@ -7,6 +7,7 @@
#include <stdint.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/drivers/bluetooth/hci_driver.h>
#include "common/assert.h"
struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len)
{
@ -15,6 +16,8 @@ struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len)
buf = bt_buf_get_evt(evt, false, K_FOREVER);
BT_ASSERT(buf);
hdr = net_buf_add(buf, sizeof(*hdr));
hdr->evt = evt;
hdr->len = len;