]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
serial: tty: uartlite: fix console setup
authorDaniel Mack <daniel@zonque.org>
Fri, 28 May 2021 13:33:20 +0000 (15:33 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Mon, 20 Sep 2021 16:48:50 +0000 (18:48 +0200)
BugLink: https://bugs.launchpad.net/bugs/1939440
[ Upstream commit d157fca711ad42e75efef3444c83d2e1a17be27a ]

Remove the hack to assign the global console_port variable at probe time.
This assumption that cons->index is -1 is wrong for systems that specify
'console=' in the cmdline (or 'stdout-path' in dts). Hence, on such system
the actual console assignment is ignored, and the first UART that happens
to be probed is used as console instead.

Move the logic to console_setup() and map the console to the correct port
through the array of available ports instead.

Signed-off-by: Daniel Mack <daniel@zonque.org>
Link: https://lore.kernel.org/r/20210528133321.1859346-1-daniel@zonque.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/tty/serial/uartlite.c

index 06e79c11141d440347aa8d6c7d41b777f1c2febe..56066d93a65b856bd104477c11db3ce53a3bec89 100644 (file)
@@ -508,21 +508,23 @@ static void ulite_console_write(struct console *co, const char *s,
 
 static int ulite_console_setup(struct console *co, char *options)
 {
-       struct uart_port *port;
+       struct uart_port *port = NULL;
        int baud = 9600;
        int bits = 8;
        int parity = 'n';
        int flow = 'n';
 
-
-       port = console_port;
+       if (co->index >= 0 && co->index < ULITE_NR_UARTS)
+               port = ulite_ports + co->index;
 
        /* Has the device been initialized yet? */
-       if (!port->mapbase) {
+       if (!port || !port->mapbase) {
                pr_debug("console on ttyUL%i not present\n", co->index);
                return -ENODEV;
        }
 
+       console_port = port;
+
        /* not initialized yet? */
        if (!port->membase) {
                if (ulite_request_port(port))
@@ -658,17 +660,6 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
 
        dev_set_drvdata(dev, port);
 
-#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
-       /*
-        * If console hasn't been found yet try to assign this port
-        * because it is required to be assigned for console setup function.
-        * If register_console() don't assign value, then console_port pointer
-        * is cleanup.
-        */
-       if (ulite_uart_driver.cons->index == -1)
-               console_port = port;
-#endif
-
        /* Register the port */
        rc = uart_add_one_port(&ulite_uart_driver, port);
        if (rc) {
@@ -678,12 +669,6 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
                return rc;
        }
 
-#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
-       /* This is not port which is used for console that's why clean it up */
-       if (ulite_uart_driver.cons->index == -1)
-               console_port = NULL;
-#endif
-
        return 0;
 }