diff options
author | Patrick Delaunay <patrick.delaunay@st.com> | 2018-08-03 14:38:43 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2018-09-11 03:20:34 +0300 |
commit | d3bb7858545fa54ff3c591570f1d36234ecde2bf (patch) | |
tree | 38ccac62ceb5957d25a71707c3423b2fde263d9a /drivers/serial/serial-uclass.c | |
parent | fe852bc109f13664b9d733501f2c4ae33a4c7d3e (diff) | |
download | u-boot-d3bb7858545fa54ff3c591570f1d36234ecde2bf.tar.xz |
serial: protect access to serial rx buffer
Add test to avoid access to rx buffer when this buffer is empty.
In this case directly call getc() function to avoid issue when tstc()
is not called.
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/serial/serial-uclass.c')
-rw-r--r-- | drivers/serial/serial-uclass.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 321d23ee93..4121a37aa8 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -228,6 +228,9 @@ static int _serial_getc(struct udevice *dev) struct serial_dev_priv *upriv = dev_get_uclass_priv(dev); char val; + if (upriv->rd_ptr == upriv->wr_ptr) + return __serial_getc(dev); + val = upriv->buf[upriv->rd_ptr++]; upriv->rd_ptr %= CONFIG_SERIAL_RX_BUFFER_SIZE; |