[PATCH 2/4] ASoC: codecs: mt6358: Fix Avdd supply leak across card bind/unbind

From: Arina Kharlamova via B4 Relay

Date: Tue Dec 01 2026 - 14:12:21 EST


From: Arina Kharlamova <arina.kharlamova@xxxxxxxxxxxx>

mt6358_codec_probe() gets the Avdd supply with devm_regulator_get() on
the platform device and enables it, but the component has no remove
callback and the supply is never disabled. The component probe runs on
every card bind, while the devres of the platform device is released
only when the codec driver is unbound. Each card bind therefore adds
another regulator consumer and another enable, and the supply stays
enabled after the card is gone. When the codec driver is unbound,
_regulator_put() hits WARN_ON(regulator->enable_count) for each of
them.

Get the regulator once in the platform probe, so that it is released
after the component is unregistered, and disable it in a new component
remove callback.

Fixes: 6a8d4198ca80 ("ASoC: mediatek: mt6358: add codec driver")
Signed-off-by: Arina Kharlamova <arina.kharlamova@xxxxxxxxxxxx>
---
sound/soc/codecs/mt6358.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/mt6358.c b/sound/soc/codecs/mt6358.c
index 42b131dc5107..69f6040473c4 100644
--- a/sound/soc/codecs/mt6358.c
+++ b/sound/soc/codecs/mt6358.c
@@ -2338,12 +2338,6 @@ static int mt6358_codec_probe(struct snd_soc_component *cmpnt)

mt6358_codec_init_reg(priv);

- priv->avdd_reg = devm_regulator_get(priv->dev, "Avdd");
- if (IS_ERR(priv->avdd_reg)) {
- dev_err(priv->dev, "%s() have no Avdd supply", __func__);
- return PTR_ERR(priv->avdd_reg);
- }
-
ret = regulator_enable(priv->avdd_reg);
if (ret)
return ret;
@@ -2351,8 +2345,16 @@ static int mt6358_codec_probe(struct snd_soc_component *cmpnt)
return 0;
}

+static void mt6358_codec_remove(struct snd_soc_component *cmpnt)
+{
+ struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
+
+ regulator_disable(priv->avdd_reg);
+}
+
static const struct snd_soc_component_driver mt6358_soc_component_driver = {
.probe = mt6358_codec_probe,
+ .remove = mt6358_codec_remove,
.controls = mt6358_snd_controls,
.num_controls = ARRAY_SIZE(mt6358_snd_controls),
.dapm_widgets = mt6358_dapm_widgets,
@@ -2393,6 +2395,11 @@ static int mt6358_platform_driver_probe(struct platform_device *pdev)
if (IS_ERR(priv->regmap))
return PTR_ERR(priv->regmap);

+ priv->avdd_reg = devm_regulator_get(priv->dev, "Avdd");
+ if (IS_ERR(priv->avdd_reg))
+ return dev_err_probe(priv->dev, PTR_ERR(priv->avdd_reg),
+ "failed to get Avdd supply\n");
+
mt6358_parse_dt(priv);

dev_info(priv->dev, "%s(), dev name %s\n",

--
Git-157)