[PATCH 19/21] ASoC: rt1011: Free the bq/drc coefficient arrays on component remove
From: Chancel Liu
Date: Mon Sep 21 2026 - 07:45:24 EST
From: Chancel Liu <chancel.liu@xxxxxxx>
component->dev is the underlying i2c device whose devres is only
released on physical device removal, not on ASoC card unbind. The
bq_drc_params arrays allocated in the component probe with
devm_kcalloc(component->dev, ...) therefore leak on every card
bind/unbind cycle.
Allocate the arrays with kcalloc() and free them in the component
remove callback.
Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
---
sound/soc/codecs/rt1011.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
index d47b0370dd6b..c140c079838d 100644
--- a/sound/soc/codecs/rt1011.c
+++ b/sound/soc/codecs/rt1011.c
@@ -2053,29 +2053,45 @@ static int rt1011_probe(struct snd_soc_component *component)
schedule_work(&rt1011->cali_work);
rt1011->i2s_ref = 0;
- rt1011->bq_drc_params = devm_kcalloc(component->dev,
- RT1011_ADVMODE_NUM, sizeof(struct rt1011_bq_drc_params *),
- GFP_KERNEL);
+ rt1011->bq_drc_params = kcalloc(RT1011_ADVMODE_NUM,
+ sizeof(struct rt1011_bq_drc_params *),
+ GFP_KERNEL);
if (!rt1011->bq_drc_params)
return -ENOMEM;
for (i = 0; i < RT1011_ADVMODE_NUM; i++) {
- rt1011->bq_drc_params[i] = devm_kcalloc(component->dev,
- RT1011_BQ_DRC_NUM, sizeof(struct rt1011_bq_drc_params),
- GFP_KERNEL);
+ rt1011->bq_drc_params[i] = kcalloc(RT1011_BQ_DRC_NUM,
+ sizeof(struct rt1011_bq_drc_params),
+ GFP_KERNEL);
if (!rt1011->bq_drc_params[i])
- return -ENOMEM;
+ goto err;
}
return 0;
+
+err:
+ while (i--)
+ kfree(rt1011->bq_drc_params[i]);
+ kfree(rt1011->bq_drc_params);
+ rt1011->bq_drc_params = NULL;
+
+ return -ENOMEM;
}
static void rt1011_remove(struct snd_soc_component *component)
{
struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
+ int i;
cancel_work_sync(&rt1011->cali_work);
rt1011_reset(rt1011->regmap);
+
+ if (rt1011->bq_drc_params) {
+ for (i = 0; i < RT1011_ADVMODE_NUM; i++)
+ kfree(rt1011->bq_drc_params[i]);
+ kfree(rt1011->bq_drc_params);
+ rt1011->bq_drc_params = NULL;
+ }
}
#ifdef CONFIG_PM
--
2.50.1