From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796296313; b=vqwuGDwOa+1uQU0TGtKie+miwWBV47lhzy/FO3+qvAkTRm02cnCjuXpcndHUx5iI7xhc J3Abp6CeXmPX1Vv3piZ6VkXDY3ryRQnuNwHoyVziUtTiRnikPg1lrgIiOq1jIdG0KvD6I eNBNr8/xGHJ29pDIJWJlbCMtjG4vCZ1lCOzlqDAWQugYYDbbaTa+pWtae5p32aaKUTRwA oftPVxVe643Bt/YPZvkC0G/1fTphozNyVgdHurl4tlS+i2PkDSSqS62M+qvavI9CUdmWr mnWu6dpU0M68h1dOFNvwmB5agnDnL1lOziloMMkKxN19uu6Mgn3JJr0AKCeWdfK8N/A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796296313; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=fe3atExzeI5pvIKsil41iSC9uOxUmFmC2nsGGL+Js7k=; b=FMHRHVxNouGNEP/Xc+/WNYxb7BzRq4QEDUio8jFadLt2HRecphJsH64XEixpbpgynai8 8ara/ztSePw42/zJex+5eUItnj93SZiMBjwvJZs6rtdwUDRZ7KxX8rYJgSlvY8EtV4awt n+xwxILfIOV5WDjSp/j13Ynj87xmBUu2K5WtZiBmSYU9cgshXph4E90qJRkri/N3wWVtG YTg76Alnva1nLD/LQv5S6aCZMr9g62F/To4/s7A0lXdoQwvKuk6B+NniXvcqfqpQSKXTe ThwDWUXm0bT8RL04E86Lgzpn8QicoZrWB8nY88+UT53ZtpWkTsbQ95c9jspfAHxghZw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SEGlivoQ; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DA2D606A32F; Thu, 3 Dec 2026 11:11:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SEGlivoQ Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796296313; b=Hk1hepfiTDevqVahDiy61NeD35MkdUQUGTcEjK7rgZTlotBuiSVegtYnwmz+hL3HHb1v qZmToh2wYlRLGswvMviFgZ5ftLwsHS4lcRYtnVdYUE45J5Uj2vzdkv7L3rr6363dNHbQM IPEpweN5whcU4j0pc0DFjZoJXrz4/DOn+iBzPFNyUF24AyR52RZe/phKUGebvtomV+Q4i yYzklVYXn3wjg39udQwlipe437lYNGxRk0BCzc6lmA7fg+00h5lL09um8jZmsN0FBik9j MtJBI14mKL09UMfj2wHsDYwTYttscDZyM74Cilu7GI5Ry84pLp1AwBOdgxRuYmQe9yA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796296313; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=fe3atExzeI5pvIKsil41iSC9uOxUmFmC2nsGGL+Js7k=; b=MRqGFb+Z/emjgxJ1XJ1Ck1Ui/zHwvOd2Cyym0bKFCfgvtNeqn4RPd8Iql0n4o83BZOhH 4bUS26qSiTiELBFxWezMFiZrkkmgqn8aGWY2n1MaBhkukOxJxNX8fLDcuy+p+heXzYB6Y //HQi6XIqi4rRfxw10aPqGS1wcsPSmDWElEUr4Ia0/SMIFV2i4lZ6+WVXBB/dmjL+T4ak Zb5jWX8JyQwLPKflWruKwy+LOYUEtZbBoMznHpDLZpPzsNC7KMAaUAszn7VDOCI5ivz+p g92l9dW6JmIDKw2daoaeD+3Ixt6kYUl1FPE/C7eriaxD9+8jAlql7gkVfdF750tnUvQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id A28A11F00893; Thu, 3 Dec 2026 11:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796296313; bh=fe3atExzeI5pvIKsil41iSC9uOxUmFmC2nsGGL+Js7k=; h=From:Date:Subject:To:Cc:Reply-To; b=SEGlivoQWzkKLfDcXzvG3phmbEMEekN2KGYOGMopEcCrgEXKqY/ZXRA1N75wmIUGX 32lgpP3UAqOTeSKUrHCM7efjoTgusyY8lq6oYmr7Zn3yYqVy/MBVbnW0jp/lkM8ia6 xURymlltsLp8+HuZy9wBSMydf0C7qGBZflsPIoUPDIc5RWXZHmkA+zh/00+UAxzhMI v6Gsi5oOaTw/62gEmc3qzYMOPU9SWvw6ZputKcPcbnvEe4blCUGOZG96Sx5+81mcwj G/xlXDGttsD5leGlYe6SaBWmHemKJwAjmas6HZBGK+k1jsvzKdpTDMYTB2JA908w/q rXvAOrVwu8XsQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 1E7614F8C3; Thu, 3 Dec 2026 11:11:52 +0000 (UTC) From: Arina Kharlamova via B4 Relay Date: Thu, 03 Dec 2026 15:11:44 +0400 Subject: [PATCH v2] serial: mvebu-uart: do not leave a stale port behind when probe fails X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261203-v08b-v2-1-79564cfdbb46@mbzuai.ac.ae> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/12Nyw7CIBBFf6WZtTRA0FhX/kfTBY/BjomtgZaoD f8u1J3Lk5x77gYRA2GES7NBwESR5qmAPDRgRz3dkJErDJLLk5BcsMTPhnHvvNJHhZ2SUNRnQE+ vPdMPP46ruaNd6rYaI8VlDu/9J4nq/SWTYIJp5xRH03mPeH2Yz6qp1bbVCEPO+QtSS9vJrQAAA A== X-Change-ID: 20261201-v08b-0fdf4a54e942 To: =?utf-8?q?Pali_Roh=C3=A1r?= , Greg Kroah-Hartman , Jiri Slaby , Gregory CLEMENT , Wilson Ding Cc: Miquel Raynal , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Arina Kharlamova X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796296311; l=4889; i=arina.kharlamova@mbzuai.ac.ae; s=20261123; h=from:subject:message-id; bh=TpJ+tS+hGc5Kqgp5wuWwQyoKaC3T8eaznsysqaoo1Ms=; b=tZsIX7boziIBRDeG5C+ZD/puuDDuTKREP2xWN78NEKIddeOgMi8lokptWQ4RdvRx1MiRZt0g1 7JK6EqHc2ZFBRQaKKGiHx+frLVJps/VNo+0QAlNCxKKVf2jJC0hXsRV X-Developer-Key: i=arina.kharlamova@mbzuai.ac.ae; a=ed25519; pk=DzQWwMpUtJvSDuzprqvRdbrC72n4Sq8dW6cq3NRt2Mk= X-Endpoint-Received: by B4 Relay for arina.kharlamova@mbzuai.ac.ae/20261123 with auth_id=1625 X-Original-From: Arina Kharlamova Reply-To: arina.kharlamova@mbzuai.ac.ae Content-Transfer-Encoding: 7bit From: Arina Kharlamova 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 --- 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@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. --- 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. - Link to v1: https://patch.msgid.link/20261201-v08b-v1-1-add40eb9ffee@mbzuai.ac.ae --- drivers/tty/serial/mvebu-uart.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/mvebu-uart.c b/drivers/tty/serial/mvebu-uart.c index 8a61517d81f2..5ea513555998 100644 --- a/drivers/tty/serial/mvebu-uart.c +++ b/drivers/tty/serial/mvebu-uart.c @@ -868,10 +868,11 @@ 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; - 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"); @@ -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, ®); - if (IS_ERR(port->membase)) - return PTR_ERR(port->membase); - port->mapbase = reg->start; + base = devm_platform_get_and_ioremap_resource(pdev, 0, ®); + if (IS_ERR(base)) + return PTR_ERR(base); mvuart = devm_kzalloc_obj(&pdev->dev, struct mvebu_uart); if (!mvuart) @@ -921,7 +921,6 @@ static int mvebu_uart_probe(struct platform_device *pdev) mvuart->data = (struct mvebu_uart_driver_data *)match->data; mvuart->port = port; - port->private_data = mvuart; platform_set_drvdata(pdev, mvuart); /* Get fixed clock frequency */ @@ -930,7 +929,7 @@ static int mvebu_uart_probe(struct platform_device *pdev) if (PTR_ERR(mvuart->clk) == -EPROBE_DEFER) return PTR_ERR(mvuart->clk); - if (IS_EXTENDED(port)) { + if (mvuart->data->is_ext) { dev_err(&pdev->dev, "unable to get UART clock\n"); return PTR_ERR(mvuart->clk); } @@ -966,12 +965,23 @@ static int mvebu_uart_probe(struct platform_device *pdev) mvuart->irq[UART_TX_IRQ] = irq; } + port->private_data = mvuart; + port->membase = base; + port->mapbase = reg->start; + /* UART Soft Reset*/ writel(CTRL_SOFT_RST, port->membase + UART_CTRL(port)); udelay(1); writel(0, port->membase + UART_CTRL(port)); - return uart_add_one_port(&mvebu_uart_driver, port); + ret = uart_add_one_port(&mvebu_uart_driver, port); + if (ret) { + port->mapbase = 0; + port->membase = NULL; + port->private_data = NULL; + } + + return ret; } static struct mvebu_uart_driver_data uart_std_driver_data = { --- base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 change-id: 20261201-v08b-0fdf4a54e942 Best regards, -- Arina Kharlamova