[PATCH 09/20] ASoC: ssm4567: Unwind failed power restoration

Pengpeng Hou <[email protected]>
Newsgroups gmane.linux.sound,gmane.linux.kernel
Message-ID <[email protected]>
ssm4567_set_power() leaves the regmap live when soft reset or the
power-register update fails, and ignores the following cache replay
result.

Handle all three failures through one path that restores cache-only and
dirty state before returning the error to the DAPM bias caller.

The issue was identified via static analysis and manually reviewed.

Fixes: 1ee44ce03011 ("ASoC: ssm4567: Add driver for Analog Devices SSM4567 amplifier")

Assisted-by: LLM
Signed-off-by: Pengpeng Hou <[email protected]>
---
 sound/soc/codecs/ssm4567.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/ssm4567.c b/sound/soc/codecs/ssm4567.c
index 8415dd163edd..2783bff77c72 100644
--- a/sound/soc/codecs/ssm4567.c
+++ b/sound/soc/codecs/ssm4567.c
@@ -354,14 +354,25 @@ static int ssm4567_set_power(struct ssm4567 *ssm4567, bool enable)
 		ret = regmap_write(ssm4567->regmap, SSM4567_REG_SOFT_RESET,
 			0x00);
 		if (ret)
-			return ret;
+			goto err_power_off;
 
 		ret = regmap_update_bits(ssm4567->regmap,
 			SSM4567_REG_POWER_CTRL,
 			SSM4567_POWER_SPWDN, 0x00);
-		regcache_sync(ssm4567->regmap);
+		if (ret)
+			goto err_power_off;
+
+		ret = regcache_sync(ssm4567->regmap);
+		if (ret)
+			goto err_power_off;
 	}
 
+	return ret;
+
+err_power_off:
+	regcache_cache_only(ssm4567->regmap, true);
+	regcache_mark_dirty(ssm4567->regmap);
+
 	return ret;
 }
 
-- 
2.43.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.