[PATCH v2 5/9] ASoC: rt5682s: restore safe state after resume errors

From: Pengpeng Hou

Date: Tue Oct 13 2026 - 23:27:00 EST


rt5682s_resume() ignores regcache_sync() failure before continuing
dependent resume operations. Restore cache-only mode, leave the cache
dirty, and return the replay error before those operations.

Do not schedule jack-detection work or enable its IRQ after a failed
replay.

ASoC still marks the component resumed when the callback reports failure.
Track the suspend-owned IRQ disable so another suspend does not increment
the disable depth again after a failed resume. A later successful resume
releases that one disable reference. This does not add automatic retry or
change the framework's best-effort card resume policy.

The issue was found by our static-analysis tool and manually reviewed.

Fixes: bdd229ab26be ("ASoC: rt5682s: Add driver for ALC5682I-VS codec")
Assisted-by: gpt 5
Signed-off-by: Pengpeng Hou <hppiscas@xxxxxxx>
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- send as one correctly threaded series, as Mark requested

Previous series:
https://lore.kernel.org/all/20260906034321.86080-1-hppiscas@xxxxxxx/

sound/soc/codecs/rt5682s.c | 16 +++++++++++++---
sound/soc/codecs/rt5682s.h | 1 +
2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/rt5682s.c b/sound/soc/codecs/rt5682s.c
index 49ed7793d3a205cd0544ea8b50dd80cbba74b9da..0c669833df7c1565de6d4428fea47af597c7294d 100644
--- a/sound/soc/codecs/rt5682s.c
+++ b/sound/soc/codecs/rt5682s.c
@@ -2884,8 +2884,10 @@ static int rt5682s_suspend(struct snd_soc_component *component)
{
struct rt5682s_priv *rt5682s = snd_soc_component_get_drvdata(component);

- if (rt5682s->irq)
+ if (rt5682s->irq && !rt5682s->suspend_irq_disabled) {
disable_irq(rt5682s->irq);
+ rt5682s->suspend_irq_disabled = true;
+ }

cancel_delayed_work_sync(&rt5682s->jack_detect_work);
cancel_delayed_work_sync(&rt5682s->jd_check_work);
@@ -2902,17 +2904,25 @@ static int rt5682s_suspend(struct snd_soc_component *component)
static int rt5682s_resume(struct snd_soc_component *component)
{
struct rt5682s_priv *rt5682s = snd_soc_component_get_drvdata(component);
+ int ret;

regcache_cache_only(rt5682s->regmap, false);
- regcache_sync(rt5682s->regmap);
+ ret = regcache_sync(rt5682s->regmap);
+ if (ret) {
+ regcache_cache_only(rt5682s->regmap, true);
+ regcache_mark_dirty(rt5682s->regmap);
+ return ret;
+ }

if (rt5682s->hs_jack) {
mod_delayed_work(system_power_efficient_wq,
&rt5682s->jack_detect_work, msecs_to_jiffies(0));
}

- if (rt5682s->irq)
+ if (rt5682s->suspend_irq_disabled) {
+ rt5682s->suspend_irq_disabled = false;
enable_irq(rt5682s->irq);
+ }

return 0;
}
diff --git a/sound/soc/codecs/rt5682s.h b/sound/soc/codecs/rt5682s.h
index 67f42898de9679679a97ff6a6b65e4b3100c9b59..a9da00e8df78293ec6c5f982682c3d55a23d88bb 100644
--- a/sound/soc/codecs/rt5682s.h
+++ b/sound/soc/codecs/rt5682s.h
@@ -1482,6 +1482,7 @@ struct rt5682s_priv {

int jack_type;
unsigned int irq;
+ bool suspend_irq_disabled;
int irq_work_delay_time;
int wclk_enabled;
};

base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6