[PATCH 09/21] ASoC: rt5640: Move mclk acquisition to the i2c probe

From: Chancel Liu

Date: Mon Sep 21 2026 - 07:54:22 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 therefore leaks a clk reference on every card
bind/unbind cycle.

Move the devm_clk_get_optional() to rt5640_i2c_probe() so the clk
reference is tied to the physical device lifetime.

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

diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index 03d0ac3359f5..1a45346cf6b9 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -2667,11 +2667,6 @@ static int rt5640_probe(struct snd_soc_component *component)
bool dmic_en = false;
u32 val;

- /* Check if MCLK provided */
- rt5640->mclk = devm_clk_get_optional(component->dev, "mclk");
- if (IS_ERR(rt5640->mclk))
- return PTR_ERR(rt5640->mclk);
-
rt5640->component = component;

snd_soc_dapm_force_bias_level(dapm, SND_SOC_BIAS_OFF);
@@ -3053,6 +3048,11 @@ static int rt5640_i2c_probe(struct i2c_client *i2c)
regmap_update_bits(rt5640->regmap, RT5640_GCTL1,
RT5640_MCLK_DET, RT5640_MCLK_DET);

+ /* Check if MCLK provided */
+ rt5640->mclk = devm_clk_get_optional(&i2c->dev, "mclk");
+ if (IS_ERR(rt5640->mclk))
+ return PTR_ERR(rt5640->mclk);
+
rt5640->hp_mute = true;
rt5640->irq = i2c->irq;
INIT_DELAYED_WORK(&rt5640->bp_work, rt5640_button_press_work);
--
2.50.1