[PATCH 08/20] ASoC: ssm2518: Unwind failed power restoration

From: Pengpeng Hou

Date: Fri Aug 28 2026 - 07:36:46 EST


ssm2518_set_power() enables the external GPIO and live regmap before
clearing software power-down and replaying the cache. The cache result
is ignored, and the first register failure also leaves the partial
enable state in place.

Send both failures through one path that restores cache-only and dirty
state and deasserts the enable GPIO before returning to the DAPM bias
caller.

The issue was identified via static analysis and manually reviewed.

Fixes: b6b5e76bb8bb ("ASoC: Add ssm2518 support")

Assisted-by: LLM
Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
sound/soc/codecs/ssm2518.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/ssm2518.c b/sound/soc/codecs/ssm2518.c
index 5192569ba6a8..ae28b0cae58c 100644
--- a/sound/soc/codecs/ssm2518.c
+++ b/sound/soc/codecs/ssm2518.c
@@ -490,10 +490,23 @@ static int ssm2518_set_power(struct ssm2518 *ssm2518, bool enable)
if (enable) {
ret = regmap_update_bits(ssm2518->regmap, SSM2518_REG_POWER1,
SSM2518_POWER1_SPWDN | SSM2518_POWER1_RESET, 0x00);
- regcache_sync(ssm2518->regmap);
+ if (ret)
+ goto err_power_off;
+
+ ret = regcache_sync(ssm2518->regmap);
+ if (ret)
+ goto err_power_off;
}

return ret;
+
+err_power_off:
+ regcache_cache_only(ssm2518->regmap, true);
+ regcache_mark_dirty(ssm2518->regmap);
+ if (ssm2518->enable_gpio)
+ gpiod_set_value_cansleep(ssm2518->enable_gpio, 0);
+
+ return ret;
}

static int ssm2518_set_bias_level(struct snd_soc_component *component,
--
2.43.0