[PATCH 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read
From: Vladimir Bely
Date: Sat Nov 28 2026 - 19:20:03 EST
Both q6asm_write_async() and q6asm_read() increment port->dsp_buf and
release ac->lock before calling apr_send_pkt(). If apr_send_pkt() fails
(for instance with -EAGAIN when the SMD FIFO is full), port->dsp_buf
has already advanced past the unsent period, leaving subsequent retries
permanently off by one period in the ring buffer.
apr_send_pkt() is already atomic-safe (it only takes the leaf
adev->svc.lock around rpmsg_trysend()). Keep ac->lock held across
apr_send_pkt() and advance port->dsp_buf only when the packet is
successfully queued.
Fixes: 68fd8480bb7b ("ASoC: qdsp6: q6asm: Add support to audio stream apis")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Vladimir Bely <vlwwwwww@xxxxxxxxx>
---
sound/soc/qcom/qdsp6/q6asm.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index ee1930e41..d4c1cff3f 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -1552,17 +1552,17 @@ int q6asm_read(struct audio_client *ac, uint32_t stream_id)
read->seq_id = port->dsp_buf;
pkt->hdr.token = port->dsp_buf;
- port->dsp_buf++;
-
- if (port->dsp_buf >= port->num_periods)
- port->dsp_buf = 0;
-
- spin_unlock_irqrestore(&ac->lock, flags);
rc = apr_send_pkt(ac->adev, pkt);
- if (rc == pkt_size)
+ if (rc == pkt_size) {
rc = 0;
- else
+ port->dsp_buf++;
+ if (port->dsp_buf >= port->num_periods)
+ port->dsp_buf = 0;
+ } else {
pr_err("read op[0x%x]rc[%d]\n", pkt->hdr.opcode, rc);
+ }
+
+ spin_unlock_irqrestore(&ac->lock, flags);
return rc;
}
@@ -1673,15 +1673,15 @@ int q6asm_write_async(struct audio_client *ac, uint32_t stream_id, uint32_t len,
write->flags = wflags;
- port->dsp_buf++;
-
- if (port->dsp_buf >= port->num_periods)
- port->dsp_buf = 0;
-
- spin_unlock_irqrestore(&ac->lock, flags);
rc = apr_send_pkt(ac->adev, pkt);
- if (rc == pkt_size)
+ if (rc == pkt_size) {
rc = 0;
+ port->dsp_buf++;
+ if (port->dsp_buf >= port->num_periods)
+ port->dsp_buf = 0;
+ }
+
+ spin_unlock_irqrestore(&ac->lock, flags);
return rc;
}
--
2.43.0