Skip to content

Commit 6b6eddc

Browse files
ISCAS-Vulabbroonie
authored andcommitted
ASoC: cs4271: Fix regulator leak on probe failure
The probe function enables regulators at the beginning but fails to disable them in its error handling path. If any operation after enabling the regulators fails, the probe will exit with an error, leaving the regulators permanently enabled, which could lead to a resource leak. Add a proper error handling path to call regulator_bulk_disable() before returning an error. Fixes: 9a397f4 ("ASoC: cs4271: add regulator consumer support") Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn> Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://patch.msgid.link/20251105062246.1955-1-vulab@iscas.ac.cn Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 249d96b commit 6b6eddc

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

sound/soc/codecs/cs4271.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,17 @@ static int cs4271_component_probe(struct snd_soc_component *component)
581581

582582
ret = regcache_sync(cs4271->regmap);
583583
if (ret < 0)
584-
return ret;
584+
goto err_disable_regulator;
585585

586586
ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
587587
CS4271_MODE2_PDN | CS4271_MODE2_CPEN,
588588
CS4271_MODE2_PDN | CS4271_MODE2_CPEN);
589589
if (ret < 0)
590-
return ret;
590+
goto err_disable_regulator;
591591
ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
592592
CS4271_MODE2_PDN, 0);
593593
if (ret < 0)
594-
return ret;
594+
goto err_disable_regulator;
595595
/* Power-up sequence requires 85 uS */
596596
udelay(85);
597597

@@ -601,6 +601,10 @@ static int cs4271_component_probe(struct snd_soc_component *component)
601601
CS4271_MODE2_MUTECAEQUB);
602602

603603
return 0;
604+
605+
err_disable_regulator:
606+
regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies);
607+
return ret;
604608
}
605609

606610
static void cs4271_component_remove(struct snd_soc_component *component)

0 commit comments

Comments
 (0)