[PATCH] ASoC: codecs: arizona-jack: Balance MICVDD and runtime PM on MICD errors

Ruoyu Wang posted 1 patch an hour ago
sound/soc/codecs/arizona-jack.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] ASoC: codecs: arizona-jack: Balance MICVDD and runtime PM on MICD errors
Posted by Ruoyu Wang an hour ago
arizona_start_mic() takes a runtime PM reference and enables MICVDD
before enabling microphone detection. If regmap_update_bits_check()
fails, it only reports the error and leaves both references held.

A later arizona_stop_mic() only releases them when clearing
ARIZONA_MICD_ENA changes the register. An error before MICD is enabled
therefore keeps the device active and MICVDD enabled indefinitely.

Release MICVDD and the runtime PM reference on error, just as for a
successful update which reports no change.

This issue was found by a static analysis checker and confirmed by
manual source review.

Fixes: fbdc60b2a787 ("extcon: arizona: Correct error handling on regmap_update_bits_check")
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 sound/soc/codecs/arizona-jack.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/arizona-jack.c b/sound/soc/codecs/arizona-jack.c
index a9063bac2752b..ec291174660db 100644
--- a/sound/soc/codecs/arizona-jack.c
+++ b/sound/soc/codecs/arizona-jack.c
@@ -272,9 +272,10 @@ static void arizona_start_mic(struct arizona_priv *info)
 	ret = regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
 				       ARIZONA_MICD_ENA, ARIZONA_MICD_ENA,
 				       &change);
-	if (ret < 0) {
+	if (ret < 0)
 		dev_err(arizona->dev, "Failed to enable micd: %d\n", ret);
-	} else if (!change) {
+
+	if (ret < 0 || !change) {
 		regulator_disable(info->micvdd);
 		pm_runtime_put_autosuspend(arizona->dev);
 	}
-- 
2.51.0