From 43314ffae53b813c6a0d6e34723921316cf46f45 Mon Sep 17 00:00:00 2001 From: Werner Zeh Date: Wed, 17 May 2017 10:13:24 +0200 Subject: uart: Fix bug in {uart8250, uart8250_mem, ns16550}_rx_byte functions We have several different UART implementations of which three support a timeout when receiving characters. In all of these three implementations there is a bug where when the timeout is hit the last received character will be returned instead of the needed 0. The problem is that the timeout variable i is decremented after it has been checked in the while-loop. That leads to the fact that when the while-loop is aborted due to a timeout i will contain 0xffffffff and not 0. Thus in turn will fool the following if-statement leading to wrong return value to the caller in this case. Therefore the caller will see a received character event if there is none. Change-Id: I23ff531a1e729e816764f1a071484c924dcb0f85 Signed-off-by: Werner Zeh Reviewed-on: https://review.coreboot.org/19731 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/soc/broadcom/cygnus/ns16550.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/soc') diff --git a/src/soc/broadcom/cygnus/ns16550.c b/src/soc/broadcom/cygnus/ns16550.c index 71a4cb08ef..aa9dd2d818 100644 --- a/src/soc/broadcom/cygnus/ns16550.c +++ b/src/soc/broadcom/cygnus/ns16550.c @@ -84,8 +84,10 @@ static int ns16550_tst_byte(void) static unsigned char ns16550_rx_byte(void) { unsigned long int i = SINGLE_CHAR_TIMEOUT; - while (i-- && !ns16550_tst_byte()) + while (i && !ns16550_tst_byte()) { udelay(1); + i--; + } if (i) return read32(®s->rbr); else -- cgit v1.2.3