[PATCH 07/21] ASoC: es8311: Move mclk acquisition to the i2c probe
From: Chancel Liu
Date: Mon Sep 21 2026 - 06:55: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 es8311_i2c_probe() so the clk
reference is tied to the i2c device lifetime.
Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
---
sound/soc/codecs/es8311.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/es8311.c b/sound/soc/codecs/es8311.c
index e46b85f11d57..ddbbfc2443b3 100644
--- a/sound/soc/codecs/es8311.c
+++ b/sound/soc/codecs/es8311.c
@@ -906,12 +906,6 @@ static int es8311_component_probe(struct snd_soc_component *component)
es8311 = snd_soc_component_get_drvdata(component);
- es8311->mclk = devm_clk_get_optional(component->dev, "mclk");
- if (IS_ERR(es8311->mclk)) {
- dev_err(component->dev, "invalid mclk\n");
- return PTR_ERR(es8311->mclk);
- }
-
es8311->mclk_freq = clk_get_rate(es8311->mclk);
if (es8311->mclk_freq > 0 && es8311->mclk_freq < ES8311_MCLK_MAX_FREQ)
es8311_set_sysclk_constraints(es8311->mclk_freq, es8311);
@@ -960,6 +954,10 @@ static int es8311_i2c_probe(struct i2c_client *i2c_client)
if (es8311 == NULL)
return -ENOMEM;
+ es8311->mclk = devm_clk_get_optional(dev, "mclk");
+ if (IS_ERR(es8311->mclk))
+ return dev_err_probe(dev, PTR_ERR(es8311->mclk), "invalid mclk\n");
+
es8311->regmap =
devm_regmap_init_i2c(i2c_client, &es8311_regmap_config);
if (IS_ERR(es8311->regmap))
--
2.50.1