[PATCH 1/6] ASoC: bcm: bcm63xx-pcm-whistler: Fix dma_desc leak and double free

Arina Kharlamova via B4 Relay devnull+arina.kharlamova.mbzuai.ac.ae at kernel.org
Tue Dec 1 11:23:32 PST 2026


From: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>

bcm63xx_pcm_hw_params() allocates a new i2s_dma_desc on every call and
stores it as the DMA data of the CPU DAI. The PCM core allows
hw_params to be called again in the SETUP and PREPARED states without
a hw_free in between, so the descriptor from the previous call is
overwritten and leaked.

bcm63xx_pcm_hw_free() frees the descriptor but leaves the pointer in
the DAI. hw_free can run again without a new allocation, for example
when snd_pcm_hw_params() fails in snd_pcm_hw_refine() and calls the
hw_free op from its error path. The stale pointer is then passed to
kfree() a second time.

Keep the existing descriptor when hw_params is called again, and clear
the DAI DMA data after the descriptor has been freed.

Fixes: 88eb404ccc3e ("ASoC: brcm: Add DSL/PON SoC audio driver")
Signed-off-by: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
---
 sound/soc/bcm/bcm63xx-pcm-whistler.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sound/soc/bcm/bcm63xx-pcm-whistler.c b/sound/soc/bcm/bcm63xx-pcm-whistler.c
index a40f6bed69c6..3449525dfaf7 100644
--- a/sound/soc/bcm/bcm63xx-pcm-whistler.c
+++ b/sound/soc/bcm/bcm63xx-pcm-whistler.c
@@ -48,6 +48,10 @@ static int bcm63xx_pcm_hw_params(struct snd_soc_component *component,
 	struct i2s_dma_desc *dma_desc;
 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
 
+	dma_desc = snd_soc_dai_get_dma_data(snd_soc_rtd_to_cpu(rtd, 0), substream);
+	if (dma_desc)
+		return 0;
+
 	dma_desc = kzalloc_obj(*dma_desc, GFP_NOWAIT);
 	if (!dma_desc)
 		return -ENOMEM;
@@ -65,6 +69,7 @@ static int bcm63xx_pcm_hw_free(struct snd_soc_component *component,
 
 	dma_desc = snd_soc_dai_get_dma_data(snd_soc_rtd_to_cpu(rtd, 0), substream);
 	kfree(dma_desc);
+	snd_soc_dai_set_dma_data(snd_soc_rtd_to_cpu(rtd, 0), substream, NULL);
 
 	return 0;
 }

-- 
Git-157)





More information about the Linux-rockchip mailing list