[PATCH] ASoC: codecs: wcd-common: bound interrupt status retries

From: Jizhou Tong

Date: Sun Nov 22 2026 - 01:25:12 EST


wcd_interrupt_callback() reads three status registers after dispatching
the codec interrupt. It ignores read errors, so the loop condition can
use an uninitialized value or a value from the previous pass. A status
bit that stays set can also keep the callback looping while SoundWire
holds sdw_dev_lock.

Return on the first failed read. Allow up to ten dispatches for status
to clear, matching the SoundWire alert handler's retry budget. If a bit
remains set, log a rate-limited error and return -ETIMEDOUT.

Signed-off-by: Jizhou Tong <fqwqf@xxxxxxxxx>
---
Built wcd-common.o with ARCH=arm64 W=1 on the base below. A userspace
test of the callback covered injected regmap read errors, status
clearing on the final pass, and each register remaining pending.

sound/soc/codecs/wcd-common.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/wcd-common.c b/sound/soc/codecs/wcd-common.c
index 9016e97458..7c2d96ace0 100644
--- a/sound/soc/codecs/wcd-common.c
+++ b/sound/soc/codecs/wcd-common.c
@@ -15,6 +15,8 @@

#include "wcd-common.h"

+#define WCD_IRQ_MAX_RETRIES 10
+
#define WCD_MIN_MICBIAS_MV 1000
#define WCD_DEF_MICBIAS_MV 1800
#define WCD_MAX_MICBIAS_MV 2850
@@ -127,16 +129,27 @@ int wcd_interrupt_callback(struct sdw_slave *slave, struct irq_domain *slave_irq
{
struct regmap *regmap = dev_get_regmap(&slave->dev, NULL);
u32 sts1, sts2, sts3;
+ int ret, i;

- do {
+ /* A failed read or a stuck status must not hold sdw_dev_lock forever. */
+ for (i = 0; i < WCD_IRQ_MAX_RETRIES; i++) {
handle_nested_irq(irq_find_mapping(slave_irq, 0));
- regmap_read(regmap, wcd_intr_status0, &sts1);
- regmap_read(regmap, wcd_intr_status1, &sts2);
- regmap_read(regmap, wcd_intr_status2, &sts3);
+ ret = regmap_read(regmap, wcd_intr_status0, &sts1);
+ if (ret)
+ return ret;
+ ret = regmap_read(regmap, wcd_intr_status1, &sts2);
+ if (ret)
+ return ret;
+ ret = regmap_read(regmap, wcd_intr_status2, &sts3);
+ if (ret)
+ return ret;

- } while (sts1 || sts2 || sts3);
+ if (!(sts1 || sts2 || sts3))
+ return IRQ_HANDLED;
+ }

- return IRQ_HANDLED;
+ dev_err_ratelimited(&slave->dev, "interrupt status did not clear\n");
+ return -ETIMEDOUT;
}
EXPORT_SYMBOL_GPL(wcd_interrupt_callback);


base-commit: 7884221ca9857a317bf4bd81ac3bf5528f266feb