mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vladimir Bely <vlwwwwww@gmail.com>
To: Srinivas Kandagatla <srini@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org, Vladimir Bely <vlwwwwww@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/2] ASoC: qcom: q6asm: don't advance dsp_buf on failed write or read
Date: Sun, 29 Nov 2026 03:19:50 +0300	[thread overview]
Message-ID: <20261129001951.991080-2-vlwwwwww@gmail.com> (raw)
In-Reply-To: <20261129001951.991080-1-vlwwwwww@gmail.com>

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@vger.kernel.org
Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
 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


  reply	other threads:[~2026-11-29  0:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  0:19 [PATCH 0/2] ASoC: qcom: qdsp6: handle SMD FIFO -EAGAIN in q6asm playback Vladimir Bely
2026-11-29  0:19 ` Vladimir Bely [this message]
2026-11-29  0:19 ` [PATCH 2/2] ASoC: qcom: q6asm-dai: retry playback queuing on -EAGAIN Vladimir Bely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129001951.991080-2-vlwwwwww@gmail.com \
    --to=vlwwwwww@gmail.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=srini@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®