Skip to content

Commit 9079db2

Browse files
krzkbroonie
authored andcommitted
ASoC: codecs: wcd9335: Fix missing free of regulator supplies
Driver gets and enables all regulator supplies in probe path (wcd9335_parse_dt() and wcd9335_power_on_reset()), but does not cleanup in final error paths and in unbind (missing remove() callback). This leads to leaked memory and unbalanced regulator enable count during probe errors or unbind. Fix this by converting entire code into devm_regulator_bulk_get_enable() which also greatly simplifies the code. Fixes: 20aedaf ("ASoC: wcd9335: add support to wcd9335 codec") Cc: [email protected] Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://patch.msgid.link/20250526-b4-b4-asoc-wcd9395-vdd-px-fixes-v1-1-0b8a2993b7d3@linaro.org Signed-off-by: Mark Brown <[email protected]>
1 parent f4ba2ea commit 9079db2

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

sound/soc/codecs/wcd9335.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ struct wcd9335_codec {
332332

333333
int intr1;
334334
struct gpio_desc *reset_gpio;
335-
struct regulator_bulk_data supplies[WCD9335_MAX_SUPPLY];
336335

337336
unsigned int rx_port_value[WCD9335_RX_MAX];
338337
unsigned int tx_port_value[WCD9335_TX_MAX];
@@ -355,6 +354,10 @@ struct wcd9335_irq {
355354
char *name;
356355
};
357356

357+
static const char * const wcd9335_supplies[] = {
358+
"vdd-buck", "vdd-buck-sido", "vdd-tx", "vdd-rx", "vdd-io",
359+
};
360+
358361
static const struct wcd9335_slim_ch wcd9335_tx_chs[WCD9335_TX_MAX] = {
359362
WCD9335_SLIM_TX_CH(0),
360363
WCD9335_SLIM_TX_CH(1),
@@ -4989,30 +4992,16 @@ static int wcd9335_parse_dt(struct wcd9335_codec *wcd)
49894992
if (IS_ERR(wcd->native_clk))
49904993
return dev_err_probe(dev, PTR_ERR(wcd->native_clk), "slimbus clock not found\n");
49914994

4992-
wcd->supplies[0].supply = "vdd-buck";
4993-
wcd->supplies[1].supply = "vdd-buck-sido";
4994-
wcd->supplies[2].supply = "vdd-tx";
4995-
wcd->supplies[3].supply = "vdd-rx";
4996-
wcd->supplies[4].supply = "vdd-io";
4997-
4998-
ret = regulator_bulk_get(dev, WCD9335_MAX_SUPPLY, wcd->supplies);
4995+
ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(wcd9335_supplies),
4996+
wcd9335_supplies);
49994997
if (ret)
5000-
return dev_err_probe(dev, ret, "Failed to get supplies\n");
4998+
return dev_err_probe(dev, ret, "Failed to get and enable supplies\n");
50014999

50025000
return 0;
50035001
}
50045002

50055003
static int wcd9335_power_on_reset(struct wcd9335_codec *wcd)
50065004
{
5007-
struct device *dev = wcd->dev;
5008-
int ret;
5009-
5010-
ret = regulator_bulk_enable(WCD9335_MAX_SUPPLY, wcd->supplies);
5011-
if (ret) {
5012-
dev_err(dev, "Failed to get supplies: err = %d\n", ret);
5013-
return ret;
5014-
}
5015-
50165005
/*
50175006
* For WCD9335, it takes about 600us for the Vout_A and
50185007
* Vout_D to be ready after BUCK_SIDO is powered up.

0 commit comments

Comments
 (0)