UPSTREAM: 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.
BUG=none
BRANCH=none
TEST=none
Change-Id: I9b846abcdbc3b0e4777ff541dbb0ae7aa9f5f8d5
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Original-Commit-Id: 43314ffae5
Original-Change-Id: I23ff531a1e729e816764f1a071484c924dcb0f85
Original-Signed-off-by: Werner Zeh <werner.zeh@siemens.com>
Original-Reviewed-on: https://review.coreboot.org/19731
Original-Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/508780
Commit-Ready: Patrick Georgi <pgeorgi@chromium.org>
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
This commit is contained in:
parent
cd2dd27a79
commit
c3ed2b3013
3 changed files with 8 additions and 3 deletions
|
|
@ -62,7 +62,8 @@ static int uart8250_can_rx_byte(unsigned base_port)
|
|||
static unsigned char uart8250_rx_byte(unsigned base_port)
|
||||
{
|
||||
unsigned long int i = SINGLE_CHAR_TIMEOUT;
|
||||
while (i-- && !uart8250_can_rx_byte(base_port));
|
||||
while (i && !uart8250_can_rx_byte(base_port))
|
||||
i--;
|
||||
|
||||
if (i)
|
||||
return inb(base_port + UART8250_RBR);
|
||||
|
|
|
|||
|
|
@ -82,8 +82,10 @@ static int uart8250_mem_can_rx_byte(void *base)
|
|||
static unsigned char uart8250_mem_rx_byte(void *base)
|
||||
{
|
||||
unsigned long int i = SINGLE_CHAR_TIMEOUT;
|
||||
while (i-- && !uart8250_mem_can_rx_byte(base))
|
||||
while (i && !uart8250_mem_can_rx_byte(base)) {
|
||||
udelay(1);
|
||||
i--;
|
||||
}
|
||||
if (i)
|
||||
return uart8250_read(base, UART8250_RBR);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue