Skip to contentSkip to conversation

ASoC: es9356: defer IRQ readiness until cache replay

PATCH In review Pengpeng Hou 2 participants 2 messages Oct 14 – Oct 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ASoC: es9356: defer IRQ readiness until cache replay

For a SoundWire peripheral that remained attached, resume clears disable_irq before waiting for initialization and replaying the cache. That can permit deferred interrupt work before register restoration has succeeded.

Move this attached-device IRQ readiness update after successful cache replay and protect it with disable_irq_lock. Preserve the entry-time unattach_request condition because sdw_slave_wait_for_init() clears it. The reattachment initialization path keeps its separate behavior.

Return cache replay errors with cache-only mode restored and the cache marked dirty. Use explicit braces around the scoped guard so its internal control flow cannot bind an else from the surrounding condition.

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

Assisted-by gpt 5

---
Changes since the earlier 20-patch series member:
- regenerate the complete fix against current sound/for-next; the earlier applied commit is no longer retained in the target tree
- fix the scoped-guard/dangling-else issue reported by Mark and the 0-day CI
- preserve the pre-wait attached/reattaching distinction explicitly
- restore cache-only mode after replay failure

Previous version:
https://lore.kernel.org/all/[email protected]/

 sound/soc/codecs/es9356.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
sound/soc/codecs/es9356.c +14 -4
index 80db0f2f4aef624ecdc145d89272e04bebc2de62..fc423ec829f468e663f65039913286086b31e66d 100644
@@ -1105,11 +1105,9 @@ static int es9356_sdca_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct es9356_sdw_priv *es9356 = dev_get_drvdata(dev);
+	bool restore_irq = !slave->unattach_request;
 	int ret;
 
-	if (!slave->unattach_request)
-		es9356->disable_irq = false;
-
 	ret = sdw_slave_wait_for_init(slave, es9356_PROBE_TIMEOUT);
 	if (ret) {
 		sdw_show_ping_status(slave->bus, true);
@@ -1117,7 +1115,19 @@ static int es9356_sdca_dev_resume(struct device *dev)
 	}
 
 	regcache_cache_only(es9356->regmap, false);
-	regcache_sync(es9356->regmap);
+	ret = regcache_sync(es9356->regmap);
+	if (ret) {
+		regcache_cache_only(es9356->regmap, true);
+		regcache_mark_dirty(es9356->regmap);
+		return ret;
+	}
+
+	if (restore_irq) {
+		scoped_guard(mutex, &es9356->disable_irq_lock) {
+			es9356->disable_irq = false;
+		}
+	}
+
 	return 0;
 }
 

base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6

maintainer
#1 lore raw
Quoted 5 lines · Pengpeng Hou

For a SoundWire peripheral that remained attached, resume clears disable_irq before waiting for initialization and replaying the cache. That can permit deferred interrupt work before register restoration has succeeded.

Quoted 8 lines

Move this attached-device IRQ readiness update after successful cache replay and protect it with disable_irq_lock. Preserve the entry-time unattach_request condition because sdw_slave_wait_for_init() clears it. The reattachment initialization path keeps its separate behavior.

Return cache replay errors with cache-only mode restored and the cache marked dirty. Use explicit braces around the scoped guard so its internal control flow cannot bind an else from the surrounding condition.

You're shifting the disable_irq to after the register cache has been restored which makes sense but I'm not seeing what ensures that any interrupts that arrive before then are processed - for example one that arrives while the cache is being replayed. I think scheduling the interrupt handler should kick things but I didn't check carefully.