Commit 28fb1a92 authored by Valentin Caron's avatar Valentin Caron Committed by Greg Kroah-Hartman

serial: stm32: remove infinite loop possibility in putchar function

Rework stm32_usart_console_putchar() function in order to anticipate
the case where the character can never be sent.
Signed-off-by: default avatarValentin Caron <valentin.caron@foss.st.com>
Link: https://lore.kernel.org/r/20220419085330.1178925-2-valentin.caron@foss.st.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ec66b8cf
...@@ -1640,10 +1640,16 @@ static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch ...@@ -1640,10 +1640,16 @@ static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch
{ {
struct stm32_port *stm32_port = to_stm32_port(port); struct stm32_port *stm32_port = to_stm32_port(port);
const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs;
u32 isr;
int ret;
while (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE)) ret = readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, isr,
cpu_relax(); (isr & USART_SR_TXE), 100,
STM32_USART_TIMEOUT_USEC);
if (ret != 0) {
dev_err(port->dev, "Error while sending data in UART TX : %d\n", ret);
return;
}
writel_relaxed(ch, port->membase + ofs->tdr); writel_relaxed(ch, port->membase + ofs->tdr);
} }
......
...@@ -251,6 +251,8 @@ struct stm32_usart_info stm32h7_info = { ...@@ -251,6 +251,8 @@ struct stm32_usart_info stm32h7_info = {
#define RX_BUF_P (RX_BUF_L / 2) /* dma rx buffer period */ #define RX_BUF_P (RX_BUF_L / 2) /* dma rx buffer period */
#define TX_BUF_L RX_BUF_L /* dma tx buffer length */ #define TX_BUF_L RX_BUF_L /* dma tx buffer length */
#define STM32_USART_TIMEOUT_USEC USEC_PER_SEC /* 1s timeout in µs */
struct stm32_port { struct stm32_port {
struct uart_port port; struct uart_port port;
struct clk *clk; struct clk *clk;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment