Skip to content

Commit

Permalink
serial: tty: uartlite: fix console setup
Browse files Browse the repository at this point in the history
[ Upstream commit d157fca ]

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>
  • Loading branch information
zonque authored and gregkh committed Jul 20, 2021
1 parent 5055a0a commit 34c4b57
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions drivers/tty/serial/uartlite.c
Expand Up @@ -505,21 +505,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))
Expand Down Expand Up @@ -655,17 +657,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) {
Expand All @@ -675,12 +666,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;
}

Expand Down

0 comments on commit 34c4b57

Please sign in to comment.