From: Stefan Ghetu <stefan.ghetu@nxp.com>
To: Shengjiu Wang <shengjiu.wang@gmail.com>,
Mark Brown <broonie@kernel.org>,
linux-sound@vger.kernel.org
Cc: daniel.baluta@nxp.com, Stefan Ghetu <stefan.ghetu@nxp.com>,
Xiubo Li <Xiubo.Lee@gmail.com>,
Fabio Estevam <festevam@gmail.com>,
Nicolin Chen <nicoleotsuka@gmail.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] ASoC: fsl_asrc_dma: release DMA channels on repeated
Date: Tue, 10 Nov 2026 14:07:41 +0200 [thread overview]
Message-ID: <20261110120743.6301-4-stefan.ghetu@nxp.com> (raw)
In-Reply-To: <20261110120743.6301-1-stefan.ghetu@nxp.com>
fsl_asrc_dma_hw_params() requests new DMA channels on every call and
overwrites the previous ones, which are leaked when hw_params() is
called again without hw_free(). Its Back-End error path also releases a
channel without clearing the pointer, so the following hw_free()
releases it a second time.
Release the channels of a previous call first, and clear the pointer in
the error path.
Fixes: 3117bb3109dc ("ASoC: fsl_asrc: Add ASRC ASoC CPU DAI and platform drivers")
Fixes: 36124fb19f1a ("ASoC: fsl_asrc_dma: Fix dma_chan leak when config DMA channel failed")
Signed-off-by: Stefan Ghetu <stefan.ghetu@nxp.com>
---
sound/soc/fsl/fsl_asrc_dma.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c
index b417de6abebe..5ba4bdeff019 100644
--- a/sound/soc/fsl/fsl_asrc_dma.c
+++ b/sound/soc/fsl/fsl_asrc_dma.c
@@ -124,6 +124,19 @@ static int fsl_asrc_dma_trigger(struct snd_soc_component *component,
return 0;
}
+static void fsl_asrc_dma_release_chans(struct fsl_asrc_pair *pair, u8 dir)
+{
+ if (pair->dma_chan[!dir])
+ dma_release_channel(pair->dma_chan[!dir]);
+
+ /* release dev_to_dev chan if we aren't reusing the Back-End one */
+ if (pair->dma_chan[dir] && pair->req_dma_chan)
+ dma_release_channel(pair->dma_chan[dir]);
+
+ pair->dma_chan[!dir] = NULL;
+ pair->dma_chan[dir] = NULL;
+}
+
static int fsl_asrc_dma_hw_params(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
@@ -190,6 +203,9 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component,
dma_params_fe->addr = asrc->paddr + asrc->get_fifo_addr(!dir, index);
dma_params_fe->maxburst = dma_params_be->maxburst;
+ /* hw_params() may be called again without hw_free() in between */
+ fsl_asrc_dma_release_chans(pair, dir);
+
tmp_chan = asrc->get_dma_channel(pair, !dir);
if (IS_ERR(tmp_chan)) {
dev_err(dev, "failed to request DMA channel\n");
@@ -342,6 +358,7 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component,
dev_err(dev, "failed to config DMA channel for Back-End\n");
if (pair->req_dma_chan)
dma_release_channel(pair->dma_chan[dir]);
+ pair->dma_chan[dir] = NULL;
return ret;
}
@@ -356,15 +373,7 @@ static int fsl_asrc_dma_hw_free(struct snd_soc_component *component,
struct fsl_asrc_pair *pair = runtime->private_data;
u8 dir = tx ? OUT : IN;
- if (pair->dma_chan[!dir])
- dma_release_channel(pair->dma_chan[!dir]);
-
- /* release dev_to_dev chan if we aren't reusing the Back-End one */
- if (pair->dma_chan[dir] && pair->req_dma_chan)
- dma_release_channel(pair->dma_chan[dir]);
-
- pair->dma_chan[!dir] = NULL;
- pair->dma_chan[dir] = NULL;
+ fsl_asrc_dma_release_chans(pair, dir);
return 0;
}
--
2.53.0
next prev parent reply other threads:[~2026-11-10 12:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 12:07 [PATCH 0/5] ASoC: fsl_asrc/fsl_easrc: fix memory safety issues Stefan Ghetu
2026-11-10 12:07 ` [PATCH 1/5] ASoC: fsl_asrc_m2m: fix out-of-bounds write when draining Stefan Ghetu
2026-11-10 12:07 ` [PATCH 2/5] ASoC: fsl_asrc: fix pair ownership on repeated or failed Stefan Ghetu
2026-11-10 12:07 ` Stefan Ghetu [this message]
2026-11-10 12:07 ` [PATCH 4/5] ASoC: fsl_easrc: fix context ownership on repeated Stefan Ghetu
2026-11-10 12:07 ` [PATCH 5/5] ASoC: fsl_asrc_m2m: allow only one task at a time per Stefan Ghetu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110120743.6301-4-stefan.ghetu@nxp.com \
--to=stefan.ghetu@nxp.com \
--cc=Xiubo.Lee@gmail.com \
--cc=broonie@kernel.org \
--cc=daniel.baluta@nxp.com \
--cc=festevam@gmail.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=nicoleotsuka@gmail.com \
--cc=perex@perex.cz \
--cc=shengjiu.wang@gmail.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®