From e137e13d429e47e61d34d6365c0fc5705e60cdd4 Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Thu, 21 Mar 2024 09:30:47 +0800 Subject: [PATCH] drivers: bluetooth: hci: Fix userchan insufficient buf cause dead-loop. If insufficient buf for given event, will cause dead-loop. Signed-off-by: Lingao Meng --- drivers/bluetooth/hci/userchan.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/bluetooth/hci/userchan.c b/drivers/bluetooth/hci/userchan.c index a94ca5f46be8..7c2db0348504 100644 --- a/drivers/bluetooth/hci/userchan.c +++ b/drivers/bluetooth/hci/userchan.c @@ -220,7 +220,7 @@ static void rx_thread(void *p1, void *p2, void *p3) buf = get_rx(frame_start); if (!buf) { LOG_DBG("Discard adv report due to insufficient buf"); - continue; + goto next; } buf_tailroom = net_buf_tailroom(buf); @@ -229,7 +229,7 @@ static void rx_thread(void *p1, void *p2, void *p3) LOG_ERR("Not enough space in buffer %zu/%zu", buf_add_len, buf_tailroom); net_buf_unref(buf); - continue; + goto next; } net_buf_add_mem(buf, frame_start + sizeof(packet_type), buf_add_len); @@ -237,6 +237,8 @@ static void rx_thread(void *p1, void *p2, void *p3) LOG_DBG("Calling bt_recv(%p)", buf); bt_recv(buf); + +next: len -= decoded_len; frame_start += decoded_len; }