From 224468f35b7f9386734e3e4492de41154f398941 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 28 Oct 2021 20:08:13 +0300 Subject: [PATCH] Bluetooth: drivers: h4: Fix uart_fifo_fill return value handling The return value of uart_fifo_fill could potentially be negative, so make sure the code doesn't do anything bad in that case. Fixes #39823 Signed-off-by: Johan Hedberg --- drivers/bluetooth/hci/h4.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/hci/h4.c b/drivers/bluetooth/hci/h4.c index aa1465d72d4..ba651225a1f 100644 --- a/drivers/bluetooth/hci/h4.c +++ b/drivers/bluetooth/hci/h4.c @@ -423,7 +423,11 @@ static inline void process_tx(void) } bytes = uart_fifo_fill(h4_dev, tx.buf->data, tx.buf->len); - net_buf_pull(tx.buf, bytes); + if (unlikely(bytes < 0)) { + BT_ERR("Unable to write to UART (err %d)", bytes); + } else { + net_buf_pull(tx.buf, bytes); + } if (tx.buf->len) { return;