[PATCH v2 15/21] ASoC: codecs: wm8985: Move regulator acquisition to the bus probe
From: Chancel Liu
Date: Wed Sep 23 2026 - 02:23:59 EST
From: Chancel Liu <chancel.liu@xxxxxxx>
component->dev is the underlying i2c/spi device whose devres is only
released on physical device removal, not on ASoC card unbind. Getting
the regulator supplies with devm_regulator_bulk_get(component->dev, ...)
in the component probe therefore leaks the regulator references on every
card bind/unbind cycle.
Move the devm_regulator_bulk_get() into a helper called from the i2c and
spi probes so the supplies are tied to the physical device lifetime.
Signed-off-by: Chancel Liu <chancel.liu@xxxxxxx>
---
sound/soc/codecs/wm8985.c | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c
index 877a691c188b..1e862609f5b3 100644
--- a/sound/soc/codecs/wm8985.c
+++ b/sound/soc/codecs/wm8985.c
@@ -1029,23 +1029,30 @@ static int wm8985_set_bias_level(struct snd_soc_component *component,
return 0;
}
-static int wm8985_probe(struct snd_soc_component *component)
+static int wm8985_get_regulators(struct device *dev,
+ struct wm8985_priv *wm8985)
{
size_t i;
- struct wm8985_priv *wm8985;
int ret;
- wm8985 = snd_soc_component_get_drvdata(component);
-
for (i = 0; i < ARRAY_SIZE(wm8985->supplies); i++)
wm8985->supplies[i].supply = wm8985_supply_names[i];
- ret = devm_regulator_bulk_get(component->dev, ARRAY_SIZE(wm8985->supplies),
- wm8985->supplies);
- if (ret) {
- dev_err(component->dev, "Failed to request supplies: %d\n", ret);
- return ret;
- }
+ ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(wm8985->supplies),
+ wm8985->supplies);
+ if (ret)
+ dev_err(dev, "Failed to request supplies: %d\n", ret);
+
+ return ret;
+}
+
+static int wm8985_probe(struct snd_soc_component *component)
+{
+ size_t i;
+ struct wm8985_priv *wm8985;
+ int ret;
+
+ wm8985 = snd_soc_component_get_drvdata(component);
ret = regulator_bulk_enable(ARRAY_SIZE(wm8985->supplies),
wm8985->supplies);
@@ -1176,6 +1183,10 @@ static int wm8985_spi_probe(struct spi_device *spi)
return ret;
}
+ ret = wm8985_get_regulators(&spi->dev, wm8985);
+ if (ret)
+ return ret;
+
ret = devm_snd_soc_register_component(&spi->dev,
&soc_component_dev_wm8985, &wm8985_dai, 1);
return ret;
@@ -1212,6 +1223,10 @@ static int wm8985_i2c_probe(struct i2c_client *i2c)
return ret;
}
+ ret = wm8985_get_regulators(&i2c->dev, wm8985);
+ if (ret)
+ return ret;
+
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_wm8985, &wm8985_dai, 1);
return ret;
--
2.50.1