* [PATCH] serial: mvebu-uart: disable the clock when probe fails
@ 2026-11-29 7:28 ` Arina Kharlamova via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Arina Kharlamova @ 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
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
* [PATCH] serial: mvebu-uart: disable the clock when probe fails
@ 2026-11-29 7:28 ` Arina Kharlamova via B4 Relay
0 siblings, 0 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
* Re: [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
-1 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-29 7:36 UTC (permalink / raw)
To: Arina Kharlamova; +Cc: linux-serial
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] serial: mvebu-uart: stale global port state on
mvebu_uart_probe() error [1]
--
commit 98c494846856773a61ec6f57e5851a44337bc3b6
Author: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
serial: mvebu-uart: disable the clock when probe fails
This commit registers a devres action to disable and unprepare the UART
clock when mvebu_uart_probe() fails or defers after enabling it.
> diff --git a/drivers/tty/serial/mvebu-uart.c b/drivers/tty/serial/mvebu-uart.c
> index 8a61517d81f21..d344ad2023a37 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 */
[Severity: High]
This problem wasn't introduced by this patch, but can returning on an error
or probe deferral in mvebu_uart_probe() leave dangling pointers in the
global mvebu_uart_ports[] array [1]?
Before fetching the clock or interrupts, mvebu_uart_probe() populates
mvebu_uart_ports[pdev->id] with devres-managed allocations:
drivers/tty/serial/mvebu-uart.c:mvebu_uart_probe() {
...
port = &mvebu_uart_ports[pdev->id];
...
port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, ®);
if (IS_ERR(port->membase))
return PTR_ERR(port->membase);
port->mapbase = reg->start;
mvuart = devm_kzalloc_obj(&pdev->dev, struct mvebu_uart);
if (!mvuart)
return -ENOMEM;
...
port->private_data = mvuart;
...
}
If a later step fails or defers (for example, devm_clk_get() or
platform_get_irq() returning -EPROBE_DEFER), devres unmaps port->membase
and frees mvuart, while mvebu_uart_ports[pdev->id] keeps the non-NULL
port->membase, non-zero port->mapbase, and freed port->private_data.
Because mvebu_uart_console_setup() only checks !port->mapbase ||
!port->membase before calling uart_set_options(), console setup on the
unprobed port will dereference freed memory in port->private_data and
access unmapped MMIO at port->membase.
In addition, when no DT serial alias is present, pdev->id is assigned from
uart_num_counter++, which is not rolled back on probe deferral and can
exhaust MVEBU_NR_UARTS across retries.
[1] https://sashiko.dev/#/bug/linux-289cf5cf-e5b0-49b1-9858-4b240bfa4c46
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-s2p-v08-v1-1-342b7170e692@mbzuai.ac.ae?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-29 7:36 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
2026-11-29 7:28 ` Arina Kharlamova via B4 Relay
2026-11-29 7:36 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.