[PATCH 17/21] ASoC: es8389: Move regulator and mclk acquisition to the i2c probe

From: Chancel Liu

Date: Mon Sep 21 2026 - 06:56:21 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. Getting
the core regulator supplies and the mclk with devm_*(component->dev, ...)
in the component probe therefore leaks those references on every card
bind/unbind cycle.

Move the devm_regulator_bulk_get() and devm_clk_get_optional() into the
i2c probe so the resources are tied to the physical device lifetime.

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

diff --git a/sound/soc/codecs/es8389.c b/sound/soc/codecs/es8389.c
index fe341fe56760..931577e5e29f 100644
--- a/sound/soc/codecs/es8389.c
+++ b/sound/soc/codecs/es8389.c
@@ -1076,22 +1076,6 @@ static int es8389_probe(struct snd_soc_component *component)
es8389->mclk_src = ES8389_MCLK_SOURCE;
}

- for (i = 0; i < ARRAY_SIZE(es8389_core_supplies); i++)
- es8389->core_supply[i].supply = es8389_core_supplies[i];
- ret = devm_regulator_bulk_get(component->dev, ARRAY_SIZE(es8389_core_supplies), es8389->core_supply);
- if (ret) {
- dev_err(component->dev, "Failed to request core supplies %d\n", ret);
- return ret;
- }
-
- es8389->mclk = devm_clk_get_optional(component->dev, "mclk");
- if (IS_ERR(es8389->mclk))
- return dev_err_probe(component->dev, PTR_ERR(es8389->mclk),
- "ES8389 is unable to get mclk\n");
-
- if (!es8389->mclk)
- dev_err(component->dev, "%s, assuming static mclk\n", __func__);
-
ret = clk_prepare_enable(es8389->mclk);
if (ret) {
dev_err(component->dev, "%s, unable to enable mclk\n", __func__);
@@ -1179,7 +1163,7 @@ static void es8389_i2c_shutdown(struct i2c_client *i2c)
static int es8389_i2c_probe(struct i2c_client *i2c_client)
{
struct es8389_private *es8389;
- int ret;
+ int ret, i;

es8389 = devm_kzalloc(&i2c_client->dev, sizeof(*es8389), GFP_KERNEL);
if (es8389 == NULL)
@@ -1191,6 +1175,22 @@ static int es8389_i2c_probe(struct i2c_client *i2c_client)
return dev_err_probe(&i2c_client->dev, PTR_ERR(es8389->regmap),
"regmap_init() failed\n");

+ for (i = 0; i < ARRAY_SIZE(es8389_core_supplies); i++)
+ es8389->core_supply[i].supply = es8389_core_supplies[i];
+ ret = devm_regulator_bulk_get(&i2c_client->dev, ARRAY_SIZE(es8389_core_supplies),
+ es8389->core_supply);
+ if (ret)
+ return dev_err_probe(&i2c_client->dev, ret,
+ "Failed to request core supplies\n");
+
+ es8389->mclk = devm_clk_get_optional(&i2c_client->dev, "mclk");
+ if (IS_ERR(es8389->mclk))
+ return dev_err_probe(&i2c_client->dev, PTR_ERR(es8389->mclk),
+ "ES8389 is unable to get mclk\n");
+
+ if (!es8389->mclk)
+ dev_err(&i2c_client->dev, "%s, assuming static mclk\n", __func__);
+
ret = devm_snd_soc_register_component(&i2c_client->dev,
&soc_codec_dev_es8389,
&es8389_dai,
--
2.50.1