From e3fbea00b72dc71ff64f04363c36e362267b3122 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Tue, 21 Feb 2012 12:29:03 -0800 Subject: [PATCH] uart: fix race condition in flow control The previous TX might end in the middle of the buffer filling and stop TX. So we need to check if we want to restart the transmission. With 1-byte deep FIFO, it's easy to trigger that race condition. Signed-off-by: Vincent Palatin BUG=None TEST=run console commands with lots of traces on BDS, Link and ADV and check we are not stuck. Change-Id: Ia57e974a3a51af694e736d4cf36d9d01eafd2251 --- common/uart_buffering.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/common/uart_buffering.c b/common/uart_buffering.c index 6eea74329a..b9c7f6d1ff 100644 --- a/common/uart_buffering.c +++ b/common/uart_buffering.c @@ -367,15 +367,13 @@ void uart_set_console_mode(int enable) int uart_puts(const char *outstr) { - int was_empty = (tx_buf_head == tx_buf_tail); - /* Put all characters in the output buffer */ while (*outstr) { if (__tx_char(*outstr++) != 0) break; } - if (was_empty) + if (uart_tx_stopped()) uart_tx_start(); /* Successful if we consumed all output */ @@ -392,7 +390,6 @@ int uart_printf(const char *format, ...) int is_left; int pad_zero; int pad_width; - int was_empty = (tx_buf_head == tx_buf_tail); va_list args; char *vstr; int vlen; @@ -510,7 +507,7 @@ int uart_printf(const char *format, ...) } va_end(args); - if (was_empty) + if (uart_tx_stopped()) uart_tx_start(); /* Successful if we consumed all output */