[PATCH 12/21] ASoC: rt5682s: Move mclk acquisition to the i2c probe
From: Chancel Liu
Date: Mon Sep 21 2026 - 06:55:32 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 codec clock with devm_clk_get_optional(component->dev, ...) in the
component probe chain therefore leaks a clk reference on every card
bind/unbind cycle.
Move the devm_clk_get_optional() to rt5682s_i2c_probe() so the clk
reference is tied to the physical device lifetime.
Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
---
sound/soc/codecs/rt5682s.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/sound/soc/codecs/rt5682s.c b/sound/soc/codecs/rt5682s.c
index 6dd0d36a7186..0f80e4c32f57 100644
--- a/sound/soc/codecs/rt5682s.c
+++ b/sound/soc/codecs/rt5682s.c
@@ -2846,11 +2846,6 @@ static int rt5682s_dai_probe_clks(struct snd_soc_component *component)
struct rt5682s_priv *rt5682s = snd_soc_component_get_drvdata(component);
int ret;
- /* Check if MCLK provided */
- rt5682s->mclk = devm_clk_get_optional(component->dev, "mclk");
- if (IS_ERR(rt5682s->mclk))
- return PTR_ERR(rt5682s->mclk);
-
/* Register CCF DAI clock control */
ret = rt5682s_register_dai_clks(component);
if (ret)
@@ -3152,6 +3147,13 @@ static int rt5682s_i2c_probe(struct i2c_client *i2c)
return ret;
}
+#ifdef CONFIG_COMMON_CLK
+ /* Check if MCLK provided */
+ rt5682s->mclk = devm_clk_get_optional(&i2c->dev, "mclk");
+ if (IS_ERR(rt5682s->mclk))
+ return PTR_ERR(rt5682s->mclk);
+#endif
+
for (i = 0; i < ARRAY_SIZE(rt5682s->supplies); i++)
rt5682s->supplies[i].supply = rt5682s_supply_names[i];
--
2.50.1