Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] serial: mvebu-uart: disable the clock when probe fails
@ 2026-11-29  7:28 Arina Kharlamova via B4 Relay
  2026-11-29  7:36 ` sashiko-bot
  2026-12-03 10:53 ` Miquel Raynal
  0 siblings, 2 replies; 3+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-11-29  7:28 UTC (permalink / raw)
  To: Pali Rohár, Greg Kroah-Hartman, Jiri Slaby, Gregory CLEMENT,
	Allen Yan, Miquel Raynal
  Cc: linux-kernel, linux-serial, Arina Kharlamova

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

mvebu_uart_probe() prepares and enables the UART clock, but the later
returns for a missing interrupt, including -EPROBE_DEFER from
platform_get_irq(), and for a failed uart_add_one_port() leave it
enabled. The clock comes from devm_clk_get(), so devres only puts it,
and every deferred probe raises the enable count by one more.

Disable and unprepare the clock through a devres action registered
right after it is enabled.

Fixes: 68a0db1d7da2 ("serial: mvebu-uart: add function to change baudrate")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
Found by the spec2patch formal prover, with the help of an AI coding
assistant (Claude); I reviewed the analysis and the fix.
---
 drivers/tty/serial/mvebu-uart.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/mvebu-uart.c b/drivers/tty/serial/mvebu-uart.c
index 8a61517d81f2..d344ad2023a3 100644
--- a/drivers/tty/serial/mvebu-uart.c
+++ b/drivers/tty/serial/mvebu-uart.c
@@ -864,6 +864,11 @@ static const struct of_device_id mvebu_uart_of_match[];
 /* Counter to keep track of each UART port id when not using CONFIG_OF */
 static int uart_num_counter;
 
+static void mvebu_uart_clk_disable(void *data)
+{
+	clk_disable_unprepare(data);
+}
+
 static int mvebu_uart_probe(struct platform_device *pdev)
 {
 	const struct of_device_id *match = of_match_device(mvebu_uart_of_match,
@@ -871,7 +876,7 @@ static int mvebu_uart_probe(struct platform_device *pdev)
 	struct uart_port *port;
 	struct mvebu_uart *mvuart;
 	struct resource *reg;
-	int id, irq;
+	int id, irq, ret;
 
 	/* Assume that all UART ports have a DT alias or none has */
 	id = of_alias_get_id(pdev->dev.of_node, "serial");
@@ -935,8 +940,14 @@ static int mvebu_uart_probe(struct platform_device *pdev)
 			return PTR_ERR(mvuart->clk);
 		}
 	} else {
-		if (!clk_prepare_enable(mvuart->clk))
+		if (!clk_prepare_enable(mvuart->clk)) {
+			ret = devm_add_action_or_reset(&pdev->dev,
+						       mvebu_uart_clk_disable,
+						       mvuart->clk);
+			if (ret)
+				return ret;
 			port->uartclk = clk_get_rate(mvuart->clk);
+		}
 	}
 
 	/* Manage interrupts */

---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-v08-290368f48291

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



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

end of thread, other threads:[~2026-12-03 10:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  7:28 [PATCH] serial: mvebu-uart: disable the clock when probe fails Arina Kharlamova via B4 Relay
2026-11-29  7:36 ` sashiko-bot
2026-12-03 10:53 ` Miquel Raynal

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