[PATCH v2 6/9] ASoC: rt5682: restore safe state after resume errors

From: Pengpeng Hou

Date: Tue Oct 13 2026 - 23:26:23 EST


rt5682_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.

Leave the SoundWire no-op branch unchanged; stop the I2C jack restore
path on replay failure.

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: 0ddce71c21f0 ("ASoC: rt5682: add rt5682 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
- 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/rt5682.c | 16 +++++++++++++---
sound/soc/codecs/rt5682.h | 1 +
2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/rt5682.c b/sound/soc/codecs/rt5682.c
index 1aceb08b280d6cd4eca01badbc3107b0645c8949..db3f1383f84f5abaa2dc35681c59fe3f4a6188d4 100644
--- a/sound/soc/codecs/rt5682.c
+++ b/sound/soc/codecs/rt5682.c
@@ -2962,8 +2962,10 @@ static int rt5682_suspend(struct snd_soc_component *component)
if (rt5682->is_sdw)
return 0;

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

cancel_delayed_work_sync(&rt5682->jack_detect_work);
cancel_delayed_work_sync(&rt5682->jd_check_work);
@@ -3010,12 +3012,18 @@ static int rt5682_suspend(struct snd_soc_component *component)
static int rt5682_resume(struct snd_soc_component *component)
{
struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
+ int ret;

if (rt5682->is_sdw)
return 0;

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

if (rt5682->hs_jack && (rt5682->jack_type & SND_JACK_HEADSET) == SND_JACK_HEADSET) {
snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
@@ -3033,8 +3041,10 @@ static int rt5682_resume(struct snd_soc_component *component)
mod_delayed_work(system_power_efficient_wq,
&rt5682->jack_detect_work, msecs_to_jiffies(0));

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

return 0;
}
diff --git a/sound/soc/codecs/rt5682.h b/sound/soc/codecs/rt5682.h
index de43a5d99403b926c21b2415af9022b42bf9ae8b..74356cd7fb45d84a49b6d532538ff03c529763e8 100644
--- a/sound/soc/codecs/rt5682.h
+++ b/sound/soc/codecs/rt5682.h
@@ -1466,6 +1466,7 @@ struct rt5682_priv {

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


base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6