Skip to content

Commit deeb33e

Browse files
Shubhrajyoti Dattagregkh
authored andcommitted
tty: serial: uartlite: Use dynamic array for console port
Driver console functions are using pointer to static array with fixed size. There can be only one serial console at the time which is found by register_console(). register_console() is filling cons->index to port->line value. Signed-off-by: Shubhrajyoti Datta <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5f6825d commit deeb33e

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

drivers/tty/serial/uartlite.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
#define ULITE_CONTROL_RST_RX 0x02
5656
#define ULITE_CONTROL_IE 0x10
5757

58+
/* Static pointer to console port */
59+
#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
60+
static struct uart_port *console_port;
61+
#endif
62+
5863
struct uartlite_data {
5964
const struct uartlite_reg_ops *reg_ops;
6065
struct clk *clk;
@@ -472,7 +477,7 @@ static void ulite_console_putchar(struct uart_port *port, int ch)
472477
static void ulite_console_write(struct console *co, const char *s,
473478
unsigned int count)
474479
{
475-
struct uart_port *port = &ulite_ports[co->index];
480+
struct uart_port *port = console_port;
476481
unsigned long flags;
477482
unsigned int ier;
478483
int locked = 1;
@@ -506,10 +511,8 @@ static int ulite_console_setup(struct console *co, char *options)
506511
int parity = 'n';
507512
int flow = 'n';
508513

509-
if (co->index < 0 || co->index >= ULITE_NR_UARTS)
510-
return -EINVAL;
511514

512-
port = &ulite_ports[co->index];
515+
port = console_port;
513516

514517
/* Has the device been initialized yet? */
515518
if (!port->mapbase) {
@@ -652,6 +655,17 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
652655

653656
dev_set_drvdata(dev, port);
654657

658+
#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
659+
/*
660+
* If console hasn't been found yet try to assign this port
661+
* because it is required to be assigned for console setup function.
662+
* If register_console() don't assign value, then console_port pointer
663+
* is cleanup.
664+
*/
665+
if (ulite_uart_driver.cons->index == -1)
666+
console_port = port;
667+
#endif
668+
655669
/* Register the port */
656670
rc = uart_add_one_port(&ulite_uart_driver, port);
657671
if (rc) {
@@ -661,6 +675,12 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
661675
return rc;
662676
}
663677

678+
#ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
679+
/* This is not port which is used for console that's why clean it up */
680+
if (ulite_uart_driver.cons->index == -1)
681+
console_port = NULL;
682+
#endif
683+
664684
return 0;
665685
}
666686

0 commit comments

Comments
 (0)