From: Valentin Caron <valentin.caron@foss.st.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jonathan Corbet <corbet@lwn.net> Cc: Jiri Slaby <jirislaby@kernel.org>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Alexandre Torgue <alexandre.torgue@foss.st.com>, Erwan Le Ray <erwan.leray@foss.st.com>, Valentin Caron <valentin.caron@foss.st.com>, <linux-serial@vger.kernel.org>, <linux-stm32@st-md-mailman.stormreply.com>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org> Subject: [PATCH V2 1/3] serial: stm32: remove infinite loop possibility in putchar function Date: Fri, 8 Apr 2022 14:26:34 +0200 [thread overview] Message-ID: <20220408122636.505737-2-valentin.caron@foss.st.com> (raw) In-Reply-To: <20220408122636.505737-1-valentin.caron@foss.st.com> Rework stm32_usart_console_putchar() function in order to anticipate the case where the character can never be sent. Signed-off-by: Valentin Caron <valentin.caron@foss.st.com> --- drivers/tty/serial/stm32-usart.c | 12 +++++++++--- drivers/tty/serial/stm32-usart.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 87b5cd4c9743..83895da84891 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -1645,10 +1645,16 @@ static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch { struct stm32_port *stm32_port = to_stm32_port(port); const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; + u32 isr; + int ret; - while (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE)) - cpu_relax(); - + ret = readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, isr, + (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); } diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h index feab952aec16..d734c4a5fd24 100644 --- a/drivers/tty/serial/stm32-usart.h +++ b/drivers/tty/serial/stm32-usart.h @@ -251,6 +251,8 @@ struct stm32_usart_info stm32h7_info = { #define RX_BUF_P (RX_BUF_L / 2) /* dma rx buffer period */ #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 uart_port port; struct clk *clk; -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Valentin Caron <valentin.caron@foss.st.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jonathan Corbet <corbet@lwn.net> Cc: Jiri Slaby <jirislaby@kernel.org>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Alexandre Torgue <alexandre.torgue@foss.st.com>, Erwan Le Ray <erwan.leray@foss.st.com>, Valentin Caron <valentin.caron@foss.st.com>, <linux-serial@vger.kernel.org>, <linux-stm32@st-md-mailman.stormreply.com>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org> Subject: [PATCH V2 1/3] serial: stm32: remove infinite loop possibility in putchar function Date: Fri, 8 Apr 2022 14:26:34 +0200 [thread overview] Message-ID: <20220408122636.505737-2-valentin.caron@foss.st.com> (raw) In-Reply-To: <20220408122636.505737-1-valentin.caron@foss.st.com> Rework stm32_usart_console_putchar() function in order to anticipate the case where the character can never be sent. Signed-off-by: Valentin Caron <valentin.caron@foss.st.com> --- drivers/tty/serial/stm32-usart.c | 12 +++++++++--- drivers/tty/serial/stm32-usart.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 87b5cd4c9743..83895da84891 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -1645,10 +1645,16 @@ static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch { struct stm32_port *stm32_port = to_stm32_port(port); const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; + u32 isr; + int ret; - while (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE)) - cpu_relax(); - + ret = readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, isr, + (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); } diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h index feab952aec16..d734c4a5fd24 100644 --- a/drivers/tty/serial/stm32-usart.h +++ b/drivers/tty/serial/stm32-usart.h @@ -251,6 +251,8 @@ struct stm32_usart_info stm32h7_info = { #define RX_BUF_P (RX_BUF_L / 2) /* dma rx buffer period */ #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 uart_port port; struct clk *clk; -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-04-08 12:27 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-08 12:26 [PATCH V2 0/3] serial: stm32: add earlycon and polling mode Valentin Caron 2022-04-08 12:26 ` Valentin Caron 2022-04-08 12:26 ` Valentin Caron [this message] 2022-04-08 12:26 ` [PATCH V2 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron 2022-04-08 12:26 ` [PATCH V2 2/3] serial: stm32: add KGDB support Valentin Caron 2022-04-08 12:26 ` Valentin Caron 2022-04-08 12:26 ` [PATCH V2 3/3] serial: stm32: add earlycon support Valentin Caron 2022-04-08 12:26 ` Valentin Caron 2022-04-11 14:59 ` Geert Uytterhoeven 2022-04-11 14:59 ` Geert Uytterhoeven 2022-04-14 12:17 ` Valentin CARON 2022-04-14 12:17 ` Valentin CARON 2022-04-14 12:24 ` Geert Uytterhoeven 2022-04-14 12:24 ` Geert Uytterhoeven
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220408122636.505737-2-valentin.caron@foss.st.com \ --to=valentin.caron@foss.st.com \ --cc=alexandre.torgue@foss.st.com \ --cc=corbet@lwn.net \ --cc=erwan.leray@foss.st.com \ --cc=gregkh@linuxfoundation.org \ --cc=jirislaby@kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-doc@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-serial@vger.kernel.org \ --cc=linux-stm32@st-md-mailman.stormreply.com \ --cc=mcoquelin.stm32@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.