From: sashiko-bot@kernel.org
To: "Arina Kharlamova" <arina.kharlamova@mbzuai.ac.ae>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH] serial: mvebu-uart: disable the clock when probe fails
Date: Sun, 29 Nov 2026 07:36:34 +0000 [thread overview]
Message-ID: <sashiko-outbox-239390@kernel.org> (raw)
In-Reply-To: <20261129-s2p-v08-v1-1-342b7170e692@mbzuai.ac.ae>
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
prev parent reply other threads:[~2026-11-29 7:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-239390@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=arina.kharlamova@mbzuai.ac.ae \
--cc=linux-serial@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.