From 44e311ed19a2dc23646ca62bbd83ddf046991d08 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Tue, 26 Jan 2016 14:14:21 +0200 Subject: [PATCH] Bluetooth: nble: Limit number tries when reading from UART There are situations when nble_read() might stuck reading from UART when there is no data. Limit number of tries to 10. Change-Id: I23380b622439ce9fa72b05f4eb527f03c749fce8 Signed-off-by: Andrei Emeltchenko --- drivers/nble/uart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nble/uart.c b/drivers/nble/uart.c index 44d642f3931..11f1670590b 100644 --- a/drivers/nble/uart.c +++ b/drivers/nble/uart.c @@ -116,6 +116,7 @@ static int nble_read(struct device *uart, uint8_t *buf, size_t len, size_t min) { int total = 0; + int tries = 10; while (len) { int rx; @@ -123,7 +124,7 @@ static int nble_read(struct device *uart, uint8_t *buf, rx = uart_fifo_read(uart, buf, len); if (rx == 0) { BT_DBG("Got zero bytes from UART"); - if (total < min) { + if (total < min && tries--) { continue; } break;