[PATCH 31/33] serial: 8250: invert condition to avoid a goto label

Jiri Slaby (SUSE) posted 33 patches 4 months ago
[PATCH 31/33] serial: 8250: invert condition to avoid a goto label
Posted by Jiri Slaby (SUSE) 4 months ago
Use of "goto" in this code is frowned upon:
 +-------
 |if (port->type == PORT_UNKNOWN)
 |  goto out_unlock;
 |CODE;
 |out_unlock:
 +-------

Instead, simply do:
 +-------
 |if (port->type != PORT_UNKNOWN)
 |  CODE;
 +-------

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_port.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index e93bfdac3d0e..48c30e158cb8 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1184,19 +1184,17 @@ static void autoconfig(struct uart_8250_port *up)
 	up->capabilities = uart_config[port->type].flags;
 	up->tx_loadsz = uart_config[port->type].tx_loadsz;
 
-	if (port->type == PORT_UNKNOWN)
-		goto out_unlock;
-
-	/*
-	 * Reset the UART.
-	 */
-	rsa_reset(up);
-	serial8250_out_MCR(up, save_mcr);
-	serial8250_clear_fifos(up);
-	serial_in(up, UART_RX);
-	serial8250_clear_IER(up);
+	if (port->type != PORT_UNKNOWN) {
+		/*
+		 * Reset the UART.
+		 */
+		rsa_reset(up);
+		serial8250_out_MCR(up, save_mcr);
+		serial8250_clear_fifos(up);
+		serial_in(up, UART_RX);
+		serial8250_clear_IER(up);
+	}
 
-out_unlock:
 	uart_port_unlock_irqrestore(port, flags);
 
 	/*
-- 
2.49.0
Re: [PATCH 31/33] serial: 8250: invert condition to avoid a goto label
Posted by Andy Shevchenko 3 months, 3 weeks ago
On Wed, Jun 11, 2025 at 12:03:17PM +0200, Jiri Slaby (SUSE) wrote:
> Use of "goto" in this code is frowned upon:
>  +-------
>  |if (port->type == PORT_UNKNOWN)
>  |  goto out_unlock;
>  |CODE;
>  |out_unlock:
>  +-------
> 
> Instead, simply do:
>  +-------
>  |if (port->type != PORT_UNKNOWN)
>  |  CODE;
>  +-------

Wouldn't this patch be a churn since you mentioned a guard()() conversion?
Basically with guard() in place the code would be better to change if it's
left as is.

-- 
With Best Regards,
Andy Shevchenko