Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] serial: mvebu-uart: do not leave a stale port behind when probe fails
@ 2026-12-01 19:19 Arina Kharlamova via B4 Relay
  2026-12-01 19:30 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:19 UTC (permalink / raw)
  To: Pali Rohár, Greg Kroah-Hartman, Jiri Slaby, Gregory CLEMENT,
	Miquel Raynal
  Cc: linux-kernel, linux-serial, Arina Kharlamova

From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

mvebu_uart_probe() stores the devm mapping in mvebu_uart_ports[] before
it gets the clock and the interrupts. If one of them fails or defers,
devres unmaps the registers and frees the private data, but the static
port keeps membase, mapbase and private_data.

mvebu_uart_console_setup() only checks membase and mapbase. When
another port registers the console first, for example with
console=ttyMV1 and ttyMV1 still waiting for its clock, the setup
callback uses the stale port and accesses the unmapped registers.

Keep the mapping in a local variable and store it in the port only
after the last step that can fail before uart_add_one_port().

Fixes: 68a0db1d7da2 ("serial: mvebu-uart: add function to change baudrate")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
The static port array keeps pointers into devm memory after a failed
or deferred probe. This patch only moves the assignment of membase and
mapbase. It is independent of my earlier clock patch for this driver
and applies with or without it.

I noticed this while working on "serial: mvebu-uart: disable the clock
when probe fails":
https://lore.kernel.org/r/20261129-s2p-v08-v1-1-342b7170e692@mbzuai.ac.ae
The Sashiko review pointed at it. With the help of an AI coding
assistant (Claude); I reviewed the analysis and the fix.
Compile-tested only, not tested on hardware.
---
 drivers/tty/serial/mvebu-uart.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/mvebu-uart.c b/drivers/tty/serial/mvebu-uart.c
index 8a61517d81f2..9f59fa5a706e 100644
--- a/drivers/tty/serial/mvebu-uart.c
+++ b/drivers/tty/serial/mvebu-uart.c
@@ -868,6 +868,7 @@ static int mvebu_uart_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *match = of_match_device(mvebu_uart_of_match,
 							   &pdev->dev);
+	void __iomem *base;
 	struct uart_port *port;
 	struct mvebu_uart *mvuart;
 	struct resource *reg;
@@ -908,10 +909,9 @@ static int mvebu_uart_probe(struct platform_device *pdev)
 	port->irq        = 0;
 	port->irqflags   = 0;
 
-	port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &reg);
-	if (IS_ERR(port->membase))
-		return PTR_ERR(port->membase);
-	port->mapbase    = reg->start;
+	base = devm_platform_get_and_ioremap_resource(pdev, 0, &reg);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
 
 	mvuart = devm_kzalloc_obj(&pdev->dev, struct mvebu_uart);
 	if (!mvuart)
@@ -966,6 +966,9 @@ static int mvebu_uart_probe(struct platform_device *pdev)
 		mvuart->irq[UART_TX_IRQ] = irq;
 	}
 
+	port->membase = base;
+	port->mapbase = reg->start;
+
 	/* UART Soft Reset*/
 	writel(CTRL_SOFT_RST, port->membase + UART_CTRL(port));
 	udelay(1);

---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261201-v08b-0fdf4a54e942

Best regards,
--  
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-01 19:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:19 [PATCH] serial: mvebu-uart: do not leave a stale port behind when probe fails Arina Kharlamova via B4 Relay
2026-12-01 19:30 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox