From 5cc3c8f7264ea83b2c597d3d71d1a4a4a515d65f Mon Sep 17 00:00:00 2001 From: Chancel Liu Date: Wed, 23 Sep 2026 15:12:51 +0900 Subject: [PATCH] ASoC: codecs: es8311: Move mclk acquisition to the i2c probe 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 Link: https://patch.msgid.link/20260923061305.4041197-8-chancel.liu@oss.nxp.com Signed-off-by: Mark Brown --- 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)) -- knotmirror 0.0.1