From: Mikael Magnusson <mikachu@gmail.com>
To: linux-sound@vger.kernel.org
Cc: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH v2] ALSA: pcm: update state after xrun
Date: Thu, 12 Nov 2026 10:46:36 +0100 [thread overview]
Message-ID: <20261112094636.13671-1-mikachu@gmail.com> (raw)
If the snd_pcm_update_hw_ptr call from snd_pcm_status is what triggers
the xrun state (eg, as opposed to an IRQ), the returned status->state
was stale and told userspace the device was still playing, so they could
get confused about device state and hang indefinitely.
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222201
Signed-off-by: Mikael Magnusson <mikachu@gmail.com>
---
Changes from v1:
incorporate feedback from Sashiko and Takashi:
also set the trigger_tstamp since it can change in this scenario.
check return value to determine if we need to update the status fields.
PS Sorry it took a while to send the respin, I don't have a dedicated
testing machine, and I didn't have an opportunity to reboot to test it
until now.
sound/core/pcm_native.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 1f5ebfd288..5d80b56449 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1127,7 +1127,13 @@ int snd_pcm_status64(struct snd_pcm_substream *substream,
status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec;
status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec;
if (snd_pcm_running(substream)) {
- snd_pcm_update_hw_ptr(substream);
+ if (snd_pcm_update_hw_ptr(substream) < 0) {
+ /* update_hw_ptr may have put us in xrun state, update state */
+ status->state = runtime->state;
+ status->suspended_state = runtime->suspended_state;
+ status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec;
+ status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec;
+ }
if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
status->tstamp_sec = runtime->status->tstamp.tv_sec;
status->tstamp_nsec =
--
2.38.1
next reply other threads:[~2026-11-12 9:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 9:46 Mikael Magnusson [this message]
2026-11-12 12:35 ` [PATCH v2] ALSA: pcm: update state after xrun Takashi Iwai
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=20261112094636.13671-1-mikachu@gmail.com \
--to=mikachu@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=tiwai@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.