Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 9a397f473657 ("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>

authored by

Haotian Zhang and committed by
Mark Brown
6b6eddc6 249d96b4

+7 -3
+7 -3
sound/soc/codecs/cs4271.c
··· 581 581 582 582 ret = regcache_sync(cs4271->regmap); 583 583 if (ret < 0) 584 - return ret; 584 + goto err_disable_regulator; 585 585 586 586 ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, 587 587 CS4271_MODE2_PDN | CS4271_MODE2_CPEN, 588 588 CS4271_MODE2_PDN | CS4271_MODE2_CPEN); 589 589 if (ret < 0) 590 - return ret; 590 + goto err_disable_regulator; 591 591 ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, 592 592 CS4271_MODE2_PDN, 0); 593 593 if (ret < 0) 594 - return ret; 594 + goto err_disable_regulator; 595 595 /* Power-up sequence requires 85 uS */ 596 596 udelay(85); 597 597 ··· 601 601 CS4271_MODE2_MUTECAEQUB); 602 602 603 603 return 0; 604 + 605 + err_disable_regulator: 606 + regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); 607 + return ret; 604 608 } 605 609 606 610 static void cs4271_component_remove(struct snd_soc_component *component)