]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ASoC: cs4271: Fix regulator leak on probe failure
authorHaotian Zhang <vulab@iscas.ac.cn>
Wed, 5 Nov 2025 06:22:46 +0000 (14:22 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 6 Dec 2025 21:12:34 +0000 (06:12 +0900)
[ Upstream commit 6b6eddc63ce871897d3a5bc4f8f593e698aef104 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/soc/codecs/cs4271.c

index 2021cf4426061ef7d8ced6f394c311dfcf1724b8..f6c9430612f53957078a676e7a843400938e700b 100644 (file)
@@ -594,17 +594,17 @@ static int cs4271_component_probe(struct snd_soc_component *component)
 
        ret = regcache_sync(cs4271->regmap);
        if (ret < 0)
-               return ret;
+               goto err_disable_regulator;
 
        ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
                                 CS4271_MODE2_PDN | CS4271_MODE2_CPEN,
                                 CS4271_MODE2_PDN | CS4271_MODE2_CPEN);
        if (ret < 0)
-               return ret;
+               goto err_disable_regulator;
        ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
                                 CS4271_MODE2_PDN, 0);
        if (ret < 0)
-               return ret;
+               goto err_disable_regulator;
        /* Power-up sequence requires 85 uS */
        udelay(85);
 
@@ -614,6 +614,10 @@ static int cs4271_component_probe(struct snd_soc_component *component)
                                   CS4271_MODE2_MUTECAEQUB);
 
        return 0;
+
+err_disable_regulator:
+       regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies);
+       return ret;
 }
 
 static void cs4271_component_remove(struct snd_soc_component *component)