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

Ruoyu Wang <[email protected]>
Newsgroups gmane.linux.sound,gmane.linux.kernel
Message-ID <[email protected]>
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 <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.