[PATCH 18/21] ASoC: rt5677-spi: Free the DSP context on component remove
From: Chancel Liu
Date: Mon Sep 21 2026 - 07:05:35 EST
From: Chancel Liu <chancel.liu@xxxxxxx>
component->dev is the underlying SPI bus device, whose devres lifetime
follows the physical device's probe/remove rather than the ASoC card's
bind/unbind. The rt5677_dsp context allocated in the component probe with
devm_kzalloc(component->dev, ...) therefore leaks on every card
bind/unbind cycle, and the delayed work initialised there is never
cancelled on unbind.
Allocate the context with kzalloc() and add a component .remove callback
that cancels the copy work, destroys the mutex and frees the context.
Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
---
sound/soc/codecs/rt5677-spi.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/rt5677-spi.c b/sound/soc/codecs/rt5677-spi.c
index ebc527115ea5..285ea4872cde 100644
--- a/sound/soc/codecs/rt5677-spi.c
+++ b/sound/soc/codecs/rt5677-spi.c
@@ -380,8 +380,7 @@ static int rt5677_spi_pcm_probe(struct snd_soc_component *component)
{
struct rt5677_dsp *rt5677_dsp;
- rt5677_dsp = devm_kzalloc(component->dev, sizeof(*rt5677_dsp),
- GFP_KERNEL);
+ rt5677_dsp = kzalloc_obj(*rt5677_dsp);
if (!rt5677_dsp)
return -ENOMEM;
rt5677_dsp->dev = &g_spi->dev;
@@ -392,9 +391,22 @@ static int rt5677_spi_pcm_probe(struct snd_soc_component *component)
return 0;
}
+static void rt5677_spi_pcm_remove(struct snd_soc_component *component)
+{
+ struct rt5677_dsp *rt5677_dsp =
+ snd_soc_component_get_drvdata(component);
+
+ snd_soc_component_set_drvdata(component, NULL);
+
+ cancel_delayed_work_sync(&rt5677_dsp->copy_work);
+ mutex_destroy(&rt5677_dsp->dma_lock);
+ kfree(rt5677_dsp);
+}
+
static const struct snd_soc_component_driver rt5677_spi_dai_component = {
.name = DRV_NAME,
.probe = rt5677_spi_pcm_probe,
+ .remove = rt5677_spi_pcm_remove,
.open = rt5677_spi_pcm_open,
.close = rt5677_spi_pcm_close,
.hw_params = rt5677_spi_hw_params,
--
2.50.1