[3/3] serial: stm32: defer sysrq processing
diff mbox series

Message ID 20210416140557.25177-4-johan@kernel.org
State Accepted
Commit cea37afd28f1bb7ca09a0c27e75f89cf2df9147d
Headers show
Series
  • serial: sysrq cleanup and stm32 fixes
Related show

Commit Message

Johan Hovold April 16, 2021, 2:05 p.m. UTC
Use the uart_unlock_and_check_sysrq() helper to defer sysrq processing
until receive processing is done and the port lock has been released.

This allows cleaning up the console_write() implementation by not having
to work around the recursive sysrq case (by dropping locking completely)
and also makes the console code work with PREEMPT_RT by no longer
relying on local_irq_save().

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/tty/serial/stm32-usart.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Comments

Valentin CARON - foss April 22, 2021, 9:36 a.m. UTC | #1
Hi,

On 4/16/21 4:05 PM, Johan Hovold wrote:
> Use the uart_unlock_and_check_sysrq() helper to defer sysrq processing
> until receive processing is done and the port lock has been released.
>
> This allows cleaning up the console_write() implementation by not having
> to work around the recursive sysrq case (by dropping locking completely)
> and also makes the console code work with PREEMPT_RT by no longer
> relying on local_irq_save().
>
> Signed-off-by: Johan Hovold <johan@kernel.org>

Reviewed-by: Valentin Caron<valentin.caron@foss.st.com>

> ---
>   drivers/tty/serial/stm32-usart.c | 16 ++++++----------
>   1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
> index 3524ed2c0c73..24a1dfe7058b 100644
> --- a/drivers/tty/serial/stm32-usart.c
> +++ b/drivers/tty/serial/stm32-usart.c
> @@ -270,12 +270,12 @@ static void stm32_usart_receive_chars(struct uart_port *port, bool threaded)
>   			}
>   		}
>   
> -		if (uart_handle_sysrq_char(port, c))
> +		if (uart_prepare_sysrq_char(port, c))
>   			continue;
>   		uart_insert_char(port, sr, USART_SR_ORE, c, flag);
>   	}
>   
> -	spin_unlock(&port->lock);
> +	uart_unlock_and_check_sysrq(port);
>   
>   	tty_flip_buffer_push(tport);
>   }
> @@ -1430,13 +1430,10 @@ static void stm32_usart_console_write(struct console *co, const char *s,
>   	u32 old_cr1, new_cr1;
>   	int locked = 1;
>   
> -	local_irq_save(flags);
> -	if (port->sysrq)
> -		locked = 0;
> -	else if (oops_in_progress)
> -		locked = spin_trylock(&port->lock);
> +	if (oops_in_progress)
> +		locked = spin_trylock_irqsave(&port->lock, flags);
>   	else
> -		spin_lock(&port->lock);
> +		spin_lock_irqsave(&port->lock, flags);
>   
>   	/* Save and disable interrupts, enable the transmitter */
>   	old_cr1 = readl_relaxed(port->membase + ofs->cr1);
> @@ -1450,8 +1447,7 @@ static void stm32_usart_console_write(struct console *co, const char *s,
>   	writel_relaxed(old_cr1, port->membase + ofs->cr1);
>   
>   	if (locked)
> -		spin_unlock(&port->lock);
> -	local_irq_restore(flags);
> +		spin_unlock_irqrestore(&port->lock, flags);
>   }
>   
>   static int stm32_usart_console_setup(struct console *co, char *options)

Patch
diff mbox series

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index 3524ed2c0c73..24a1dfe7058b 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -270,12 +270,12 @@  static void stm32_usart_receive_chars(struct uart_port *port, bool threaded)
 			}
 		}
 
-		if (uart_handle_sysrq_char(port, c))
+		if (uart_prepare_sysrq_char(port, c))
 			continue;
 		uart_insert_char(port, sr, USART_SR_ORE, c, flag);
 	}
 
-	spin_unlock(&port->lock);
+	uart_unlock_and_check_sysrq(port);
 
 	tty_flip_buffer_push(tport);
 }
@@ -1430,13 +1430,10 @@  static void stm32_usart_console_write(struct console *co, const char *s,
 	u32 old_cr1, new_cr1;
 	int locked = 1;
 
-	local_irq_save(flags);
-	if (port->sysrq)
-		locked = 0;
-	else if (oops_in_progress)
-		locked = spin_trylock(&port->lock);
+	if (oops_in_progress)
+		locked = spin_trylock_irqsave(&port->lock, flags);
 	else
-		spin_lock(&port->lock);
+		spin_lock_irqsave(&port->lock, flags);
 
 	/* Save and disable interrupts, enable the transmitter */
 	old_cr1 = readl_relaxed(port->membase + ofs->cr1);
@@ -1450,8 +1447,7 @@  static void stm32_usart_console_write(struct console *co, const char *s,
 	writel_relaxed(old_cr1, port->membase + ofs->cr1);
 
 	if (locked)
-		spin_unlock(&port->lock);
-	local_irq_restore(flags);
+		spin_unlock_irqrestore(&port->lock, flags);
 }
 
 static int stm32_usart_console_setup(struct console *co, char *options)