Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2AFF45BD4B for ; Wed, 21 Jan 2026 12:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768998041; cv=none; b=qNBEuAPHOd1niyW0n0KiL+rCKFm9qAF/GTo5Bozv3S7tcyYD8BudwTAvyNe8w5M1xRBx1G4WAoTtvkuLQBEfJRomYeCFuFmTm9/72ygz9sjwFJRPRd2BgGHEVJaGZIdVBuTT6ODE11D+t+Ugb5W4IJXpQn7LQ34rqmQe+JMzKXM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768998041; c=relaxed/simple; bh=PkeZAL3A4isxUpt4Z2YuTADEgBJWd8om64/ENtpYKY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MtmSU1WAVno899Fykido0d/KrPYGaD/UKaATe2OnAyAwKDmruTRaR1d6Fh2aXWU8QJOX9s1QkBzVdO0ejEzYbOsNvCWQ6UNLaYNnNzFNCYfLdcbFFL0LufILOdZ+w2B4O1CbxSBergatRrl/Ybwx3xj6Xx/u0zjLRj7GFzMUjMU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jrUn9P1K; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jrUn9P1K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64636C116D0; Wed, 21 Jan 2026 12:20:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768998041; bh=PkeZAL3A4isxUpt4Z2YuTADEgBJWd8om64/ENtpYKY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jrUn9P1KHZvmK3EypWqevNg6FrqiJinEym0ztALqBntK0SOAtXCRtmZBFIcpUE3RJ 7UcU5AVTNX/cboXyk4kw8yqPu51pat8QjVKWjxU463esliBkQUj9U9O62JDjezLhCj vYPsZUG5a4aIyjFglJpllKaL+QikwqNhIdLKhyrIADmuCAbLXl9Kq1SNJgdcejn03E JyW9Ak37EtCt+UVRTKIajAOKCoVBKtUceVqfHMN2DYXiySoUVqa2lhIbwNmh1dEDDx xznMw3tnX6kfxZ1RPpj6zNTb9Z0IdcEXeQoDM0SEHNijSwfRzRNgn+3p4MD+fw9jz5 aIkjWwkgO99CA== From: Sasha Levin To: stable@vger.kernel.org Cc: Johan Hovold , Pierre-Yves MORDRET , Amelie Delaunay , Vinod Koul , Sasha Levin Subject: [PATCH 6.1.y] dmaengine: stm32: dmamux: fix device leak on route allocation Date: Wed, 21 Jan 2026 07:20:38 -0500 Message-ID: <20260121122038.1526229-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026012057-fondling-fraternal-7292@gregkh> References: <2026012057-fondling-fraternal-7292@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Johan Hovold [ Upstream commit dd6e4943889fb354efa3f700e42739da9bddb6ef ] Make sure to drop the reference taken when looking up the DMA mux platform device during route allocation. Note that holding a reference to a device does not prevent its driver data from going away so there is no point in keeping the reference. Fixes: df7e762db5f6 ("dmaengine: Add STM32 DMAMUX driver") Cc: stable@vger.kernel.org # 4.15 Cc: Pierre-Yves MORDRET Signed-off-by: Johan Hovold Reviewed-by: Amelie Delaunay Link: https://patch.msgid.link/20251117161258.10679-11-johan@kernel.org Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/stm32-dmamux.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/dma/stm32-dmamux.c b/drivers/dma/stm32-dmamux.c index ee3cbbf510065..f0329f872aa85 100644 --- a/drivers/dma/stm32-dmamux.c +++ b/drivers/dma/stm32-dmamux.c @@ -88,23 +88,25 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec, struct stm32_dmamux_data *dmamux = platform_get_drvdata(pdev); struct stm32_dmamux *mux; u32 i, min, max; - int ret; + int ret = -EINVAL; unsigned long flags; if (dma_spec->args_count != 3) { dev_err(&pdev->dev, "invalid number of dma mux args\n"); - return ERR_PTR(-EINVAL); + goto err_put_pdev; } if (dma_spec->args[0] > dmamux->dmamux_requests) { dev_err(&pdev->dev, "invalid mux request number: %d\n", dma_spec->args[0]); - return ERR_PTR(-EINVAL); + goto err_put_pdev; } mux = kzalloc(sizeof(*mux), GFP_KERNEL); - if (!mux) - return ERR_PTR(-ENOMEM); + if (!mux) { + ret = -ENOMEM; + goto err_put_pdev; + } spin_lock_irqsave(&dmamux->lock, flags); mux->chan_id = find_first_zero_bit(dmamux->dma_inuse, @@ -131,7 +133,6 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec, dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", i - 1); if (!dma_spec->np) { dev_err(&pdev->dev, "can't get dma master\n"); - ret = -EINVAL; goto error; } @@ -158,6 +159,8 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec, dev_dbg(&pdev->dev, "Mapping DMAMUX(%u) to DMA%u(%u)\n", mux->request, mux->master, mux->chan_id); + put_device(&pdev->dev); + return mux; error: @@ -165,6 +168,9 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec, error_chan_id: kfree(mux); +err_put_pdev: + put_device(&pdev->dev); + return ERR_PTR(ret); } -- 2.51.0