[PATCH 20/21] ASoC: rt5645: Free the hardware EQ parameters on component remove

From: Chancel Liu

Date: Mon Sep 21 2026 - 06:59:02 EST


From: Chancel Liu <chancel.liu@xxxxxxx>

component->dev is the underlying I2C bus device, whose devres lifetime
follows the physical device's probe/remove rather than the ASoC card's
bind/unbind. The eq_param array was allocated in rt5645_probe() via
devm_kcalloc(component->dev, ...) but never released on component remove,
so it leaked one allocation on every card bind/unbind cycle.

Allocate eq_param with plain kcalloc() in rt5645_probe() and free it
explicitly in rt5645_remove() to keep its lifetime tied to the component.

Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
---
sound/soc/codecs/rt5645.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index bb448254275f..15d21097ed0c 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -3487,10 +3487,8 @@ static int rt5645_probe(struct snd_soc_component *component)
if (rt5645->pdata.long_name)
component->card->long_name = rt5645->pdata.long_name;

- rt5645->eq_param = devm_kcalloc(component->dev,
- RT5645_HWEQ_NUM, sizeof(struct rt5645_eq_param_s),
- GFP_KERNEL);
-
+ rt5645->eq_param = kcalloc(RT5645_HWEQ_NUM,
+ sizeof(struct rt5645_eq_param_s), GFP_KERNEL);
if (!rt5645->eq_param)
return -ENOMEM;

@@ -3503,7 +3501,12 @@ static int rt5645_probe(struct snd_soc_component *component)

static void rt5645_remove(struct snd_soc_component *component)
{
+ struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component);
+
rt5645_reset(component);
+
+ kfree(rt5645->eq_param);
+ rt5645->eq_param = NULL;
}

#ifdef CONFIG_PM
--
2.50.1