Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] ALSA: pcm: update state after xrun
@ 2026-11-12  9:46 Mikael Magnusson
  2026-11-12 12:35 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Magnusson @ 2026-11-12  9:46 UTC (permalink / raw)
  To: linux-sound; +Cc: Takashi Iwai

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-12 12:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12  9:46 [PATCH v2] ALSA: pcm: update state after xrun Mikael Magnusson
2026-11-12 12:35 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox