[PATCH 05/21] ASoC: es8316: Move mclk acquisition to the i2c probe

From: Chancel Liu

Date: Mon Sep 21 2026 - 07:09:11 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 es8316_i2c_probe() so the clk
reference is tied to the i2c device lifetime.

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

diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 59399476b9d7..5e7bf6f020e0 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -771,14 +771,6 @@ static int es8316_probe(struct snd_soc_component *component)

es8316->component = component;

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

i2c_set_clientdata(i2c_client, es8316);

+ es8316->mclk = devm_clk_get_optional(dev, "mclk");
+ if (IS_ERR(es8316->mclk))
+ return dev_err_probe(dev, PTR_ERR(es8316->mclk), "unable to get mclk\n");
+ if (!es8316->mclk)
+ dev_warn(dev, "assuming static mclk\n");
+
ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(es8316_supply_names),
es8316_supply_names);
if (ret)
--
2.50.1