drivers: bluetooth: h4: Fix check for sufficient buffer size
When alloc the evt buffer,such as the adv report, only compare the
remaining data len, should aslo consider the hdr_len, because the
hdr also copy to alloced buffer.if not consider the hdr, then
hdr + remaining data may larger than alloced buffer, because the
alloced buffer is not enough,then will assert when receive the
remaining data.
Signed-off-by: Guotao Zhang <guotao.zhang@nxp.com>
(cherry picked from commit ec970a635ea92a4307d30c122c2c89109f989055)
diff --git a/drivers/bluetooth/hci/h4.c b/drivers/bluetooth/hci/h4.c
index d3c2ea3..8945462 100644
--- a/drivers/bluetooth/hci/h4.c
+++ b/drivers/bluetooth/hci/h4.c
@@ -333,7 +333,7 @@
LOG_DBG("Allocated rx.buf %p", h4->rx.buf);
buf_tailroom = net_buf_tailroom(h4->rx.buf);
- if (buf_tailroom < h4->rx.remaining) {
+ if (buf_tailroom < (h4->rx.remaining + h4->rx.hdr_len)) {
LOG_ERR("Not enough space in buffer %u/%zu", h4->rx.remaining,
buf_tailroom);
h4->rx.discard = h4->rx.remaining;