[PATCH 01/13] serial: linflexuart: Fix locking in set_termios

Larisa Grigore posted 13 patches 1 month, 2 weeks ago
[PATCH 01/13] serial: linflexuart: Fix locking in set_termios
Posted by Larisa Grigore 1 month, 2 weeks ago
From: Radu Pirea <radu-nicolae.pirea@nxp.com>

Take the port->lock when set_termios is called, otherwise if characters
are sent while IP is in init mode, the IP will hang in an uncertain
state.

Fixes: 09864c1cdf5c ("tty: serial: Add linflexuart driver for S32V234")
Signed-off-by: Radu Pirea <radu-nicolae.pirea@nxp.com>
Signed-off-by: Larisa Grigore <larisa.grigore@oss.nxp.com>
---
 drivers/tty/serial/fsl_linflexuart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_linflexuart.c
index e70a56de1fce..5a410e2d56ac 100644
--- a/drivers/tty/serial/fsl_linflexuart.c
+++ b/drivers/tty/serial/fsl_linflexuart.c
@@ -407,6 +407,8 @@ linflex_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned long cr, old_cr, cr1;
 	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
 
+	uart_port_lock_irqsave(port, &flags);
+
 	cr = readl(port->membase + UARTCR);
 	old_cr = cr;
 
@@ -475,8 +477,6 @@ linflex_set_termios(struct uart_port *port, struct ktermios *termios,
 		cr &= ~LINFLEXD_UARTCR_PCE;
 	}
 
-	uart_port_lock_irqsave(port, &flags);
-
 	port->read_status_mask = 0;
 
 	if (termios->c_iflag & INPCK)
-- 
2.47.0
Re: [PATCH 01/13] serial: linflexuart: Fix locking in set_termios
Posted by Frank Li 1 month, 2 weeks ago
On Mon, Feb 16, 2026 at 04:01:53PM +0100, Larisa Grigore wrote:
> From: Radu Pirea <radu-nicolae.pirea@nxp.com>
>
> Take the port->lock when set_termios is called, otherwise if characters
> are sent while IP is in init mode, the IP will hang in an uncertain
> state.

According to patch, you move it before read(UARTCR). can explain why hang?

Frank
>
> Fixes: 09864c1cdf5c ("tty: serial: Add linflexuart driver for S32V234")
> Signed-off-by: Radu Pirea <radu-nicolae.pirea@nxp.com>
> Signed-off-by: Larisa Grigore <larisa.grigore@oss.nxp.com>
> ---
>  drivers/tty/serial/fsl_linflexuart.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_linflexuart.c
> index e70a56de1fce..5a410e2d56ac 100644
> --- a/drivers/tty/serial/fsl_linflexuart.c
> +++ b/drivers/tty/serial/fsl_linflexuart.c
> @@ -407,6 +407,8 @@ linflex_set_termios(struct uart_port *port, struct ktermios *termios,
>  	unsigned long cr, old_cr, cr1;
>  	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
>
> +	uart_port_lock_irqsave(port, &flags);
> +
>  	cr = readl(port->membase + UARTCR);
>  	old_cr = cr;
>
> @@ -475,8 +477,6 @@ linflex_set_termios(struct uart_port *port, struct ktermios *termios,
>  		cr &= ~LINFLEXD_UARTCR_PCE;
>  	}
>
> -	uart_port_lock_irqsave(port, &flags);
> -
>  	port->read_status_mask = 0;
>
>  	if (termios->c_iflag & INPCK)
> --
> 2.47.0
>
Re: [PATCH 01/13] serial: linflexuart: Fix locking in set_termios
Posted by Larisa Ileana Grigore 1 month, 1 week ago
On 2/16/2026 10:16 PM, Frank Li wrote:
> On Mon, Feb 16, 2026 at 04:01:53PM +0100, Larisa Grigore wrote:
>> From: Radu Pirea <radu-nicolae.pirea@nxp.com>
>>
>> Take the port->lock when set_termios is called, otherwise if characters
>> are sent while IP is in init mode, the IP will hang in an uncertain
>> state.
> 
> According to patch, you move it before read(UARTCR). can explain why hang?
> 
> Frank

Hello Frank,

Thanks for the review! This change was made to not let anyone send 
characters (for example calling `linflex_console_putchar`) while 
LINFlexD is entering INIT mode. The INIT mode is entered when setting 
LINFLEXD_LINCR1_INIT in LINCR1. UARTCR should also be protected with a 
lock since it can be modified from different other places.
I will update the commit description.

Regards,
Larisa
>>
>> Fixes: 09864c1cdf5c ("tty: serial: Add linflexuart driver for S32V234")
>> Signed-off-by: Radu Pirea <radu-nicolae.pirea@nxp.com>
>> Signed-off-by: Larisa Grigore <larisa.grigore@oss.nxp.com>
>> ---
>>   drivers/tty/serial/fsl_linflexuart.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_linflexuart.c
>> index e70a56de1fce..5a410e2d56ac 100644
>> --- a/drivers/tty/serial/fsl_linflexuart.c
>> +++ b/drivers/tty/serial/fsl_linflexuart.c
>> @@ -407,6 +407,8 @@ linflex_set_termios(struct uart_port *port, struct ktermios *termios,
>>   	unsigned long cr, old_cr, cr1;
>>   	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
>>
>> +	uart_port_lock_irqsave(port, &flags);
>> +
>>   	cr = readl(port->membase + UARTCR);
>>   	old_cr = cr;
>>
>> @@ -475,8 +477,6 @@ linflex_set_termios(struct uart_port *port, struct ktermios *termios,
>>   		cr &= ~LINFLEXD_UARTCR_PCE;
>>   	}
>>
>> -	uart_port_lock_irqsave(port, &flags);
>> -
>>   	port->read_status_mask = 0;
>>
>>   	if (termios->c_iflag & INPCK)
>> --
>> 2.47.0
>>