Re: [PATCH v2] serial: mvebu-uart: do not leave a stale port behind when probe fails

From: Miquel Raynal

Date: Thu Dec 03 2026 - 06:39:43 EST


On 03/12/2026 at 15:11:44 +04, Arina Kharlamova via B4 Relay <devnull+arina.kharlamova.mbzuai.ac.ae@xxxxxxxxxx> wrote:

> From: Arina Kharlamova <arina.kharlamova@xxxxxxxxxxxx>
>
> mvebu_uart_probe() fills the static mvebu_uart_ports[] entry with the
> devm mapping and the devm private data before it gets the clock and
> the interrupts, and keeps them if uart_add_one_port() fails. On any of
> these failures 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, accesses the unmapped registers and
> dereferences the freed private data.
>
> Keep the mapping in a local variable, test is_ext through mvuart
> instead of the port, and store membase, mapbase and private_data in
> the port only after the last step that can fail before
> uart_add_one_port(). Clear them again if uart_add_one_port() fails.
>
> Fixes: 30530791a7a0 ("serial: mvebu-uart: initial support for Armada-3700 serial port")
> Signed-off-by: Arina Kharlamova <arina.kharlamova@xxxxxxxxxxxx>
> ---
> The static port array keeps pointers into devm memory after a failed
> or deferred probe. This patch moves the assignment of membase, mapbase
> and private_data after the clock and the interrupts and clears them
> when uart_add_one_port() fails. It is independent of my earlier clock
> patch for this driver; both add the same ret variable, so the one
> applied second needs git am -3.
>
> 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@xxxxxxxxxxxx
> 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.
> ---
> Changes in v2:
> - Set private_data after the clock and the interrupts too, and clear
> membase, mapbase and private_data when uart_add_one_port() fails
> (Sashiko review).
> - Fixes: point at the commit that added the uart_add_one_port() path.
> - Drop the Reviewed-by from Miquel Raynal, the patch changed.

Not sure it changed enough to drop it.

Reviewed-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>