Re: [PATCH] mmc: mmci: fix DMA channel leak when mmc_add_host() fails

From: Ulf Hansson

Date: Fri Oct 30 2026 - 07:27:01 EST


On Fri, Oct 16, 2026 at 6:37 PM Anfernee Cao <anferneemelokc5@xxxxxxxxx> wrote:
>
> mmci_probe() calls mmci_dma_setup(), which acquires the RX and TX DMA
> channels via dma_request_chan(). These channels are not managed by
> devres, and are released only by mmci_dma_release().
>
> If the following mmc_add_host() fails, probe jumps to the clk_disable
> label, which only disables the clock. As probe then fails,
> mmci_remove() is never called, so both DMA channels are leaked.
>
> Release them by adding a dedicated unwind label, reached only after
> mmci_dma_setup().
>
> This issue was found by manual code inspection.
>
> Fixes: b38a20f29a49 ("mmc: mmci: fix return value check of mmc_add_host()")
> Cc: stable@xxxxxxxxxxxxxxx # v6.2+
> Signed-off-by: Anfernee Cao <anferneemelokc5@xxxxxxxxx>

Applied for fixes, thanks!

Kind regards
Uffe


> ---
> drivers/mmc/host/mmci.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
> index 416bdb184ed4..4db5c55b2700 100644
> --- a/drivers/mmc/host/mmci.c
> +++ b/drivers/mmc/host/mmci.c
> @@ -2477,11 +2477,13 @@ static int mmci_probe(struct amba_device *dev,
>
> ret = mmc_add_host(mmc);
> if (ret)
> - goto clk_disable;
> + goto dma_release;
>
> pm_runtime_put(&dev->dev);
> return 0;
>
> +dma_release:
> + mmci_dma_release(host);
> clk_disable:
> clk_disable_unprepare(host->clk);
> return ret;
> --
> 2.54.0.windows.1
>