[PATCH 15/21] ASoC: wm8985: Move regulator acquisition to the bus probe

From: Chancel Liu

Date: Mon Sep 21 2026 - 07:57:12 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 | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c
index 877a691c188b..70d0b8667b90 100644
--- a/sound/soc/codecs/wm8985.c
+++ b/sound/soc/codecs/wm8985.c
@@ -1029,6 +1029,18 @@ static int wm8985_set_bias_level(struct snd_soc_component *component,
return 0;
}

+static int wm8985_get_regulators(struct device *dev,
+ struct wm8985_priv *wm8985)
+{
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(wm8985->supplies); i++)
+ wm8985->supplies[i].supply = wm8985_supply_names[i];
+
+ return devm_regulator_bulk_get(dev, ARRAY_SIZE(wm8985->supplies),
+ wm8985->supplies);
+}
+
static int wm8985_probe(struct snd_soc_component *component)
{
size_t i;
@@ -1037,16 +1049,6 @@ static int wm8985_probe(struct snd_soc_component *component)

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 = regulator_bulk_enable(ARRAY_SIZE(wm8985->supplies),
wm8985->supplies);
if (ret) {
@@ -1176,6 +1178,12 @@ static int wm8985_spi_probe(struct spi_device *spi)
return ret;
}

+ ret = wm8985_get_regulators(&spi->dev, wm8985);
+ if (ret) {
+ dev_err(&spi->dev, "Failed to request supplies: %d\n", ret);
+ return ret;
+ }
+
ret = devm_snd_soc_register_component(&spi->dev,
&soc_component_dev_wm8985, &wm8985_dai, 1);
return ret;
@@ -1212,6 +1220,12 @@ static int wm8985_i2c_probe(struct i2c_client *i2c)
return ret;
}

+ ret = wm8985_get_regulators(&i2c->dev, wm8985);
+ if (ret) {
+ dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
+ return ret;
+ }
+
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_wm8985, &wm8985_dai, 1);
return ret;
--
2.50.1