Skip to content

Commit

Permalink
driver: serial: fixed the buffer underflow issue when clearing the port.
Browse files Browse the repository at this point in the history
Set DLAB bit before reading RDR to avoid buffer underflow.

Signed-off-by: Peng Li <[email protected]>
  • Loading branch information
lipengit authored and ioannisg committed Apr 15, 2021
1 parent 5540fa0 commit e28b7e0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/serial/uart_ns16550.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static int uart_ns16550_configure(const struct device *dev,
{
struct uart_ns16550_dev_data_t * const dev_data = DEV_DATA(dev);
const struct uart_ns16550_device_config * const dev_cfg = DEV_CFG(dev);

uint8_t lcr_cache;
uint8_t mdc = 0U;

/* temp for return value if error occurs in this locked region */
Expand Down Expand Up @@ -466,7 +466,10 @@ static int uart_ns16550_configure(const struct device *dev,
);

/* clear the port */
lcr_cache = INBYTE(LCR(dev));
OUTBYTE(LCR(dev), LCR_DLAB | lcr_cache);
INBYTE(RDR(dev));
OUTBYTE(LCR(dev), lcr_cache);

/* disable interrupts */
OUTBYTE(IER(dev), 0x00);
Expand Down

0 comments on commit e28b7e0

Please sign in to comment.