From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795619386; b=wvuDL+v0uzivwUM0cdlpr8B66eoa+I0RVWIk/v19z/j+2G8ZDAjmf+o9nbBTz5pP7Hfs iDw9Smq3m4cON5Ad3jUvb1Foe61/aq+w4wc9X+8nRGcbtpJUBPOMhZAmF1hGhSGCdLJqp B9b4T+ysk70qP3nopdUxhW41jUyAQFifmoLqXHlEcqxHF7RHPEEuXNVC3Si7QVqlFph9T vi8vMz9dTJSD/hmwNiNid9LHfFFAqCbERZv2DmOEIe1h9t/vx1GSZIjYtDZf1rNI/Jbo9 lWXzgqE7lgZ0CZPH3TkOleKnrYDE/oJsfiey4ta/zAze/fjHi/5H0Ilb4wX726BB38A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795619386; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=1yfiluj3EylgAwOhQGxUWE7R/s2jy6CyLNTYajz6k6o=; b=z5kwdl9Ll3KudUDOhhzKpIZc/hg/W2iQGnRUh1/YG9xUbdz0WI9grBPecH4sh1PfxeQg U9RvWtHMVJFvzSvC3wEY98qpDQ0b01B6Zb0I1bpJX9JLPY6UjbLci+FGPq/IX8F4Ktjsw XhyUc8IEwk569pquaT+EAKRgLeSw47rzeWyo6id1xd0Bu5yXuMgZXavdSe8U6Ne8+pIGs u3OOOa2aFCtkCuI6ztZr3PMuTXZ2mcq9bfQDCLYh/spPl8uYLVZnPcRRnj2uoNfDWUY7s Sm1NhZHs9TrS3x3Skoa3dR1H3/rXRV85JKIHT36yMXwk8yLakKDyQzXkU71BI/6P7tQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0nB5IaY0; arc=none 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 1A9CC606A323; Wed, 25 Nov 2026 15:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0nB5IaY0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87C6D1F000C0; Wed, 25 Nov 2026 15:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795619385; bh=1yfiluj3EylgAwOhQGxUWE7R/s2jy6CyLNTYajz6k6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0nB5IaY0n9xEWsQrkP3ECvqIJzbQxGomcITEaOYwADJs45AjZjZv4PTJMKYLgZ4FO blFRE7nKU34R4H78tUanieEJSF64SFFxrDU9aQuBTQZFutfKOFUiC1EzIpl3RPn6Z0 xdMi5k1jevv1wcJUTgD/KbmDS8/GCT80czN6C9Co= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Anfernee Cao , Ulf Hansson Subject: [PATCH 7.3 0578/1005] mmc: sunxi: fix clock and runtime PM leaks on probe failure Date: Wed, 25 Nov 2026 15:31:56 +0100 Message-ID: <20261125143835.288300542@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143821.729802100@linuxfoundation.org> References: <20261125143821.729802100@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anfernee Cao commit e35e360bd66898a977c296ab71fe4bae17ddceb7 upstream. sunxi_mmc_resource_request() enables the bus, card, output and sample clocks before returning. Several failure paths later in sunxi_mmc_probe() leave them running: - If devm_request_threaded_irq() fails, the clocks enabled by sunxi_mmc_enable() are never disabled. - If dma_alloc_coherent(), mmc_of_parse() or sunxi_mmc_init_host() fails, probe only frees the DMA buffer and the mmc_host. - If mmc_add_host() fails, runtime PM has already been enabled, but pm_runtime_disable() is never called. Besides leaking the clocks, this leaves the clock enable counts unbalanced, so a reprobe (for example after -EPROBE_DEFER) calls clk_prepare_enable() on the same clocks again. Disable the IRQ and the clocks in the probe error path, and disable runtime PM on the mmc_add_host() failure path. Also handle a failure of devm_request_threaded_irq() in sunxi_mmc_resource_request(). Tested with QEMU's orangepi-pc machine: with forced sunxi_mmc_init_host() and mmc_add_host() failures the MMC clocks stay disabled in clk_summary, and a normal probe with an emulated SD card still works. This issue was found by manual code inspection. Fixes: 3cbcb16095f9 ("mmc: sunxi: Add driver for SD/MMC hosts found on Allwinner sunxi SoCs") Fixes: 9a8e1e8cc2c0 ("mmc: sunxi: Add runtime_pm support") Cc: stable@vger.kernel.org # v4.18+ Signed-off-by: Anfernee Cao Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/sunxi-mmc.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) --- a/drivers/mmc/host/sunxi-mmc.c +++ b/drivers/mmc/host/sunxi-mmc.c @@ -1354,8 +1354,13 @@ static int sunxi_mmc_resource_request(st goto error_disable_mmc; } - return devm_request_threaded_irq(&pdev->dev, host->irq, sunxi_mmc_irq, - sunxi_mmc_handle_manual_stop, 0, "sunxi-mmc", host); + ret = devm_request_threaded_irq(&pdev->dev, host->irq, sunxi_mmc_irq, + sunxi_mmc_handle_manual_stop, 0, + "sunxi-mmc", host); + if (ret) + goto error_disable_mmc; + + return 0; error_disable_mmc: sunxi_mmc_disable(host); @@ -1385,9 +1390,11 @@ static int sunxi_mmc_probe(struct platfo host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &host->sg_dma, GFP_KERNEL); - if (!host->sg_cpu) - return dev_err_probe(&pdev->dev, -ENOMEM, - "Failed to allocate DMA descriptor mem\n"); + if (!host->sg_cpu) { + ret = dev_err_probe(&pdev->dev, -ENOMEM, + "Failed to allocate DMA descriptor mem\n"); + goto error_disable_mmc; + } if (host->cfg->ccu_has_timings_switch) { /* @@ -1467,7 +1474,7 @@ static int sunxi_mmc_probe(struct platfo ret = mmc_add_host(mmc); if (ret) - goto error_free_dma; + goto error_disable_rpm; dev_info(&pdev->dev, "initialized, max. request size: %u KB%s\n", mmc->max_req_size >> 10, @@ -1475,8 +1482,13 @@ static int sunxi_mmc_probe(struct platfo return 0; +error_disable_rpm: + pm_runtime_disable(&pdev->dev); error_free_dma: dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma); +error_disable_mmc: + disable_irq(host->irq); + sunxi_mmc_disable(host); return ret; }