提交 d3bb7858 编写于 作者: P Patrick Delaunay 提交者: Tom Rini

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: NPatrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: NSimon Glass <sjg@chromium.org>
上级 fe852bc1
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册