ALSA: pcm: fix incorrect hw_base increase

Message ID
State New
Headers show
  • ALSA: pcm: fix incorrect hw_base increase
Related show

Commit Message

Brent Lu May 15, 2020, 4:09 a.m.
The hw_base will be increased by runtime->buffer_size frames
unconditionally if the runtime->status->hw_ptr is not updated for over
half of buffer time. As the hw_base increases, so does the
runtime->status->hw_ptr which could lead to invalid return value when
user space program calls snd_pcm_avail() function.

By updating runtime->hw_ptr_jiffies each time the HWSYNC is called,
the hw_base will keep the same when buffer stall happens, so does the

Signed-off-by: Brent Lu <>
 sound/core/pcm_lib.c | 1 +
 1 file changed, 1 insertion(+)


diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 872a852..d531e1b 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -433,6 +433,7 @@  static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
 	if (runtime->status->hw_ptr == new_hw_ptr) {
+		runtime->hw_ptr_jiffies = curr_jiffies;
 		update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp);
 		return 0;