[PATCH v2 7/9] ASoC: wm8978: restore safe state after resume errors
From: Pengpeng Hou
Date: Tue Oct 13 2026 - 23:25:41 EST
wm8978_resume() ignores cache replay, bias restoration and PLL update
results, allowing subsequent resume steps to run after a failed operation.
Stop at the first failure and request SND_SOC_BIAS_OFF on the error path.
Bias OFF intentionally preserves PLL power, so also clear the power
register as system suspend does. Keep the original failure if rollback
reports another error. Restore cache-only mode and mark the cache dirty
so later accesses do not write through a partially restored device.
Re-enable write-through before a later replay attempt. A positive
update_bits() result means that
bits changed, not an error.
The bias callback currently does not propagate every register write error;
the rollback is therefore best-effort, not a claim of verified hardware
power-down. The ASoC wrapper continues its established best-effort resume.
The issue was found by our static-analysis tool and manually reviewed.
Fixes: 0d34e91596ef ("ASoC: add a WM8978 codec driver")
Assisted-by: gpt 5
Signed-off-by: Pengpeng Hou <hppiscas@xxxxxxx>
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- restore bias OFF on the error path, as Charles requested
- also turn off PLL power, matching system suspend rather than bias OFF alone
- preserve positive update_bits() success
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/20260906034321.86080-1-hppiscas@xxxxxxx/
sound/soc/codecs/wm8978.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c
index 258bc9f88f520e4de034393d39317e07e731d1ad..f5d3f26cc21790a8dfc4bf909a5fc5d56ba8f577 100644
--- a/sound/soc/codecs/wm8978.c
+++ b/sound/soc/codecs/wm8978.c
@@ -952,17 +952,40 @@ static int wm8978_resume(struct snd_soc_component *component)
{
struct wm8978_priv *wm8978 = snd_soc_component_get_drvdata(component);
struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
+ int ret, err;
/* Sync reg_cache with the hardware */
- regcache_sync(wm8978->regmap);
+ regcache_cache_only(wm8978->regmap, false);
+ ret = regcache_sync(wm8978->regmap);
+ if (ret)
+ goto restore_off;
- snd_soc_dapm_force_bias_level(dapm, SND_SOC_BIAS_STANDBY);
+ ret = snd_soc_dapm_force_bias_level(dapm, SND_SOC_BIAS_STANDBY);
+ if (ret)
+ goto restore_off;
- if (wm8978->f_pllout)
+ if (wm8978->f_pllout) {
/* Switch PLL on */
- snd_soc_component_update_bits(component, WM8978_POWER_MANAGEMENT_1, 0x20, 0x20);
+ ret = snd_soc_component_update_bits(component,
+ WM8978_POWER_MANAGEMENT_1,
+ 0x20, 0x20);
+ if (ret < 0)
+ goto restore_off;
+ }
return 0;
+
+restore_off:
+ err = snd_soc_dapm_force_bias_level(dapm, SND_SOC_BIAS_OFF);
+ if (err)
+ dev_err(component->dev, "Failed to restore bias OFF: %d\n", err);
+ /* Bias OFF preserves PLL; system suspend turns it off as well. */
+ err = snd_soc_component_write(component, WM8978_POWER_MANAGEMENT_1, 0);
+ if (err)
+ dev_err(component->dev, "Failed to disable PLL: %d\n", err);
+ regcache_cache_only(wm8978->regmap, true);
+ regcache_mark_dirty(wm8978->regmap);
+ return ret;
}
/*
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6