Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: tty: uartlite: fix console setup

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>

authored by

Daniel Mack and committed by
Greg Kroah-Hartman
d157fca7 236b26f1

+6 -21
+6 -21
drivers/tty/serial/uartlite.c
··· 505 505 506 506 static int ulite_console_setup(struct console *co, char *options) 507 507 { 508 - struct uart_port *port; 508 + struct uart_port *port = NULL; 509 509 int baud = 9600; 510 510 int bits = 8; 511 511 int parity = 'n'; 512 512 int flow = 'n'; 513 513 514 - 515 - port = console_port; 514 + if (co->index >= 0 && co->index < ULITE_NR_UARTS) 515 + port = ulite_ports + co->index; 516 516 517 517 /* Has the device been initialized yet? */ 518 - if (!port->mapbase) { 518 + if (!port || !port->mapbase) { 519 519 pr_debug("console on ttyUL%i not present\n", co->index); 520 520 return -ENODEV; 521 521 } 522 + 523 + console_port = port; 522 524 523 525 /* not initialized yet? */ 524 526 if (!port->membase) { ··· 657 655 658 656 dev_set_drvdata(dev, port); 659 657 660 - #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE 661 - /* 662 - * If console hasn't been found yet try to assign this port 663 - * because it is required to be assigned for console setup function. 664 - * If register_console() don't assign value, then console_port pointer 665 - * is cleanup. 666 - */ 667 - if (ulite_uart_driver.cons->index == -1) 668 - console_port = port; 669 - #endif 670 - 671 658 /* Register the port */ 672 659 rc = uart_add_one_port(&ulite_uart_driver, port); 673 660 if (rc) { ··· 665 674 dev_set_drvdata(dev, NULL); 666 675 return rc; 667 676 } 668 - 669 - #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE 670 - /* This is not port which is used for console that's why clean it up */ 671 - if (ulite_uart_driver.cons->index == -1) 672 - console_port = NULL; 673 - #endif 674 677 675 678 return 0; 676 679 }