[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <19c8369c-6839-1876-eefe-33dd69977707@linux.intel.com>
Date: Wed, 11 Jun 2025 14:45:54 +0300 (EEST)
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: "Jiri Slaby (SUSE)" <jirislaby@...nel.org>
cc: gregkh@...uxfoundation.org, linux-serial@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 10/33] serial: 8250: invert conditions in RSA functions
On Wed, 11 Jun 2025, Jiri Slaby (SUSE) wrote:
> The code can short-return in case something does not hold. So invert the
> conditions and return in those cases immediately. This makes the code
> flow more natural and less nested.
Ah, never mind my comment on the previous patch :-).
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
--
i.
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@...nel.org>
> ---
> drivers/tty/serial/8250/8250_port.c | 59 +++++++++++++++++------------
> 1 file changed, 34 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 233316a88df2..e7652d62ab2f 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -743,15 +743,16 @@ static int __enable_rsa(struct uart_8250_port *up)
> */
> static void enable_rsa(struct uart_8250_port *up)
> {
> - if (up->port.type == PORT_RSA) {
> - if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
> - uart_port_lock_irq(&up->port);
> - __enable_rsa(up);
> - uart_port_unlock_irq(&up->port);
> - }
> - if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
> - serial_out(up, UART_RSA_FRR, 0);
> + if (up->port.type != PORT_RSA)
> + return;
> +
> + if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
> + uart_port_lock_irq(&up->port);
> + __enable_rsa(up);
> + uart_port_unlock_irq(&up->port);
> }
> + if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
> + serial_out(up, UART_RSA_FRR, 0);
> }
>
> /*
> @@ -764,37 +765,45 @@ static void disable_rsa(struct uart_8250_port *up)
> unsigned char mode;
> int result;
>
> - if (up->port.type == PORT_RSA &&
> - up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
> - uart_port_lock_irq(&up->port);
> + if (up->port.type != PORT_RSA)
> + return;
>
> - mode = serial_in(up, UART_RSA_MSR);
> - result = !(mode & UART_RSA_MSR_FIFO);
> + if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16)
> + return;
>
> - if (!result) {
> - serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
> - mode = serial_in(up, UART_RSA_MSR);
> - result = !(mode & UART_RSA_MSR_FIFO);
> - }
> + uart_port_lock_irq(&up->port);
> + mode = serial_in(up, UART_RSA_MSR);
> + result = !(mode & UART_RSA_MSR_FIFO);
>
> - if (result)
> - up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
> - uart_port_unlock_irq(&up->port);
> + if (!result) {
> + serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
> + mode = serial_in(up, UART_RSA_MSR);
> + result = !(mode & UART_RSA_MSR_FIFO);
> }
> +
> + if (result)
> + up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
> + uart_port_unlock_irq(&up->port);
> }
>
> static void rsa_autoconfig(struct uart_8250_port *up)
> {
> /* Only probe for RSA ports if we got the region. */
> - if (up->port.type == PORT_16550A && up->probe & UART_PROBE_RSA &&
> - __enable_rsa(up))
> + if (up->port.type != PORT_16550A)
> + return;
> + if (!(up->probe & UART_PROBE_RSA))
> + return;
> +
> + if (__enable_rsa(up))
> up->port.type = PORT_RSA;
> }
>
> static void rsa_reset(struct uart_8250_port *up)
> {
> - if (up->port.type == PORT_RSA)
> - serial_out(up, UART_RSA_FRR, 0);
> + if (up->port.type != PORT_RSA)
> + return;
> +
> + serial_out(up, UART_RSA_FRR, 0);
> }
> #else
> static inline void enable_rsa(struct uart_8250_port *up) {}
>
Powered by blists - more mailing lists