Skip to content

Commit 3791ea6

Browse files
claudiubezneagregkh
authored andcommitted
serial: sh-sci: Clean sci_ports[0] after at earlycon exit
The early_console_setup() function initializes the sci_ports[0].port with an object of type struct uart_port obtained from the object of type struct earlycon_device received as argument by the early_console_setup(). It may happen that later, when the rest of the serial ports are probed, the serial port that was used as earlycon (e.g., port A) to be mapped to a different position in sci_ports[] and the slot 0 to be used by a different serial port (e.g., port B), as follows: sci_ports[0] = port A sci_ports[X] = port B In this case, the new port mapped at index zero will have associated data that was used for earlycon. In case this happens, after Linux boot, any access to the serial port that maps on sci_ports[0] (port A) will block the serial port that was used as earlycon (port B). To fix this, add early_console_exit() that clean the sci_ports[0] at earlycon exit time. Fixes: 0b0cced ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: [email protected] Signed-off-by: Claudiu Beznea <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 945def4 commit 3791ea6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

drivers/tty/serial/sh-sci.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,6 +3535,32 @@ sh_early_platform_init_buffer("earlyprintk", &sci_driver,
35353535
#ifdef CONFIG_SERIAL_SH_SCI_EARLYCON
35363536
static struct plat_sci_port port_cfg __initdata;
35373537

3538+
static int early_console_exit(struct console *co)
3539+
{
3540+
struct sci_port *sci_port = &sci_ports[0];
3541+
struct uart_port *port = &sci_port->port;
3542+
unsigned long flags;
3543+
int locked = 1;
3544+
3545+
if (port->sysrq)
3546+
locked = 0;
3547+
else if (oops_in_progress)
3548+
locked = uart_port_trylock_irqsave(port, &flags);
3549+
else
3550+
uart_port_lock_irqsave(port, &flags);
3551+
3552+
/*
3553+
* Clean the slot used by earlycon. A new SCI device might
3554+
* map to this slot.
3555+
*/
3556+
memset(sci_ports, 0, sizeof(*sci_port));
3557+
3558+
if (locked)
3559+
uart_port_unlock_irqrestore(port, flags);
3560+
3561+
return 0;
3562+
}
3563+
35383564
static int __init early_console_setup(struct earlycon_device *device,
35393565
int type)
35403566
{
@@ -3551,6 +3577,8 @@ static int __init early_console_setup(struct earlycon_device *device,
35513577
SCSCR_RE | SCSCR_TE | port_cfg.scscr);
35523578

35533579
device->con->write = serial_console_write;
3580+
device->con->exit = early_console_exit;
3581+
35543582
return 0;
35553583
}
35563584
static int __init sci_early_console_setup(struct earlycon_device *device,

0 commit comments

Comments
 (0)