[PATCH 14/20] ASoC: wm8904: Unwind resources on cache replay failure

From: Pengpeng Hou

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


wm8904_set_bias_level() enables supplies and MCLK, makes the regmap live
and then ignores regcache_sync() during OFF-to-STANDBY.

Return the error after restoring cache-only and dirty state and
disabling MCLK and supplies in reverse acquisition order.

The issue was identified via static analysis and manually reviewed.

Fixes: c133421800d9 ("ASoC: Add support for BIAS_OFF when idle to WM8904")

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

diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 9e5782e50f47..609f10f00c6b 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -1973,7 +1973,15 @@ static int wm8904_set_bias_level(struct snd_soc_component *component,
}

regcache_cache_only(wm8904->regmap, false);
- regcache_sync(wm8904->regmap);
+ ret = regcache_sync(wm8904->regmap);
+ if (ret) {
+ regcache_cache_only(wm8904->regmap, true);
+ regcache_mark_dirty(wm8904->regmap);
+ clk_disable_unprepare(wm8904->mclk);
+ regulator_bulk_disable(ARRAY_SIZE(wm8904->supplies),
+ wm8904->supplies);
+ return ret;
+ }

/* Enable bias */
snd_soc_component_update_bits(component, WM8904_BIAS_CONTROL_0,
--
2.43.0