[PATCH 06/21] ASoC: es8323: Move mclk acquisition to the i2c probe

From: Chancel Liu

Date: Mon Sep 21 2026 - 07:14:16 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 mclk with devm_clk_get_optional(component->dev, ...) in the
component probe therefore leaks a clk reference on every card
bind/unbind cycle.

Move the devm_clk_get_optional() to es8323_i2c_probe() so the clk
reference is tied to the i2c device lifetime.

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

diff --git a/sound/soc/codecs/es8323.c b/sound/soc/codecs/es8323.c
index 12fcfe017ab2..3f7fbbdb111e 100644
--- a/sound/soc/codecs/es8323.c
+++ b/sound/soc/codecs/es8323.c
@@ -671,15 +671,6 @@ static int es8323_probe(struct snd_soc_component *component)
struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component);
int ret;

- es8323->mclk = devm_clk_get_optional(component->dev, "mclk");
- if (IS_ERR(es8323->mclk)) {
- dev_err(component->dev, "unable to get mclk\n");
- return PTR_ERR(es8323->mclk);
- }
-
- if (!es8323->mclk)
- dev_warn(component->dev, "assuming static mclk\n");
-
ret = clk_prepare_enable(es8323->mclk);
if (ret) {
dev_err(component->dev, "unable to enable mclk\n");
@@ -789,6 +780,12 @@ static int es8323_i2c_probe(struct i2c_client *i2c_client)

i2c_set_clientdata(i2c_client, es8323);

+ es8323->mclk = devm_clk_get_optional(dev, "mclk");
+ if (IS_ERR(es8323->mclk))
+ return dev_err_probe(dev, PTR_ERR(es8323->mclk), "unable to get mclk\n");
+ if (!es8323->mclk)
+ dev_warn(dev, "assuming static mclk\n");
+
es8323->regmap = devm_regmap_init_i2c(i2c_client, &es8323_regmap);
if (IS_ERR(es8323->regmap))
return PTR_ERR(es8323->regmap);
--
2.50.1