All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: linux-sound@vger.kernel.org, Takashi Iwai <tiwai@suse.de>
Subject: Re: [PATCH] ALSA: pcm: update state after xrun
Date: Tue, 27 Oct 2026 15:50:35 +0100	[thread overview]
Message-ID: <87ld7j19l0.wl-tiwai@suse.de> (raw)
In-Reply-To: <20261027131233.17692-1-mikachu@gmail.com>

On Tue, 27 Oct 2026 14:12:33 +0100,
Mikael Magnusson wrote:
> 
> 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>
> ---
>  sound/core/pcm_native.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 35152fae74..62a2bea043 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -1132,6 +1132,9 @@ int snd_pcm_status64(struct snd_pcm_substream *substream,
>  	status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec;
>  	if (snd_pcm_running(substream)) {
>  		snd_pcm_update_hw_ptr(substream);
> +		/* update_hw_ptr may have put us in xrun state, update state */
> +		status->state = runtime->state;
> +		status->suspended_state = runtime->suspended_state;
>  		if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
>  			status->tstamp_sec = runtime->status->tstamp.tv_sec;
>  			status->tstamp_nsec =
> 

Thanks for the patch.  I can take this as-is, but what Sashiko
suggested in the review is also valid -- we may copy trigge_tstamp_*,
too.

Also, we don't have to always overwrite the values.  As a further
optimization, check the return value from snd_pcm_update_hw_ptr(), and
update only if it returns a negative (-EPIPE).

So, in the end, it'll be something like below.
Could you check whether this works for you?


thanks,

Takashi

-- 8< --
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1131,7 +1131,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 =


  parent reply	other threads:[~2026-10-27 14:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 13:12 [PATCH] ALSA: pcm: update state after xrun Mikael Magnusson
2026-10-27 13:23 ` sashiko-bot
2026-10-27 14:50 ` Takashi Iwai [this message]
2026-10-27 17:18   ` Mikael Magnusson

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=87ld7j19l0.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=linux-sound@vger.kernel.org \
    --cc=mikachu@gmail.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 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.