Skip to content

Commit 3e091d1

Browse files
claudiubezneagregkh
authored andcommitted
serial: sh-sci: Do not probe the serial port if its slot in sci_ports[] is in use
commit 9f7dea8 upstream. In the sh-sci driver, sci_ports[0] is used by earlycon. If the earlycon is still active when sci_probe() is called and the new serial port is supposed to map to sci_ports[0], return -EBUSY to prevent breaking the earlycon. This situation should occurs in debug scenarios, and users should be aware of the potential conflict. Fixes: 0b0cced ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> Link: https://lore.kernel.org/r/20250116182249.3828577-4-claudiu.beznea.uj@bp.renesas.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5312560 commit 3e091d1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

drivers/tty/serial/sh-sci.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct sci_port {
165165
static struct sci_port sci_ports[SCI_NPORTS];
166166
static unsigned long sci_ports_in_use;
167167
static struct uart_driver sci_uart_driver;
168+
static bool sci_uart_earlycon;
168169

169170
static inline struct sci_port *
170171
to_sci_port(struct uart_port *uart)
@@ -3450,6 +3451,7 @@ static int sci_probe_single(struct platform_device *dev,
34503451
static int sci_probe(struct platform_device *dev)
34513452
{
34523453
struct plat_sci_port *p;
3454+
struct resource *res;
34533455
struct sci_port *sp;
34543456
unsigned int dev_id;
34553457
int ret;
@@ -3479,6 +3481,26 @@ static int sci_probe(struct platform_device *dev)
34793481
}
34803482

34813483
sp = &sci_ports[dev_id];
3484+
3485+
/*
3486+
* In case:
3487+
* - the probed port alias is zero (as the one used by earlycon), and
3488+
* - the earlycon is still active (e.g., "earlycon keep_bootcon" in
3489+
* bootargs)
3490+
*
3491+
* defer the probe of this serial. This is a debug scenario and the user
3492+
* must be aware of it.
3493+
*
3494+
* Except when the probed port is the same as the earlycon port.
3495+
*/
3496+
3497+
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
3498+
if (!res)
3499+
return -ENODEV;
3500+
3501+
if (sci_uart_earlycon && sp == &sci_ports[0] && sp->port.mapbase != res->start)
3502+
return dev_err_probe(&dev->dev, -EBUSY, "sci_port[0] is used by earlycon!\n");
3503+
34823504
platform_set_drvdata(dev, sp);
34833505

34843506
ret = sci_probe_single(dev, dev_id, p, sp);
@@ -3575,6 +3597,7 @@ static int __init early_console_setup(struct earlycon_device *device,
35753597
port_cfg.type = type;
35763598
sci_ports[0].cfg = &port_cfg;
35773599
sci_ports[0].params = sci_probe_regmap(&port_cfg);
3600+
sci_uart_earlycon = true;
35783601
port_cfg.scscr = sci_serial_in(&sci_ports[0].port, SCSCR);
35793602
sci_serial_out(&sci_ports[0].port, SCSCR,
35803603
SCSCR_RE | SCSCR_TE | port_cfg.scscr);

0 commit comments

Comments
 (0)