Skip to content

Commit 1df9a2e

Browse files
Johan Hedbergjhedberg
authored andcommitted
Bluetooth: hci_raw: Fix buffer init after allocation
The code was not properly taking into account CONFIG_BT_HCI_RESERVE, which would cause buffer underruns for any HCI driver where this value defaults to non-zero. Also, all the allocation functions use the same pool, so we can map them simply to bt_buf_get_rx() instead of repeating the same code. Signed-off-by: Johan Hedberg <[email protected]>
1 parent 19e434d commit 1df9a2e

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

subsys/bluetooth/host/hci_raw.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, s32_t timeout)
5454
buf = net_buf_alloc(&hci_rx_pool, timeout);
5555

5656
if (buf) {
57+
net_buf_reserve(buf, CONFIG_BT_HCI_RESERVE);
5758
bt_buf_set_type(buf, type);
5859
}
5960

@@ -62,26 +63,12 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, s32_t timeout)
6263

6364
struct net_buf *bt_buf_get_cmd_complete(s32_t timeout)
6465
{
65-
struct net_buf *buf;
66-
67-
buf = net_buf_alloc(&hci_rx_pool, timeout);
68-
if (buf) {
69-
bt_buf_set_type(buf, BT_BUF_EVT);
70-
}
71-
72-
return buf;
66+
return bt_buf_get_rx(BT_BUF_EVT, timeout);
7367
}
7468

7569
struct net_buf *bt_buf_get_evt(u8_t evt, bool discardable, s32_t timeout)
7670
{
77-
struct net_buf *buf;
78-
79-
buf = net_buf_alloc(&hci_rx_pool, timeout);
80-
if (buf) {
81-
bt_buf_set_type(buf, BT_BUF_EVT);
82-
}
83-
84-
return buf;
71+
return bt_buf_get_rx(BT_BUF_EVT, timeout);
8572
}
8673

8774
int bt_recv(struct net_buf *buf)

0 commit comments

Comments
 (0)