[PATCH alsa-lib 3/3] pcm: direct: Check xrun/suspend before the slave hwptr update

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The xrun/suspend may happen at any time and we should check it right
before the slave hwptr update.  Otherwise the hwptr value may be
screwed and get unexpected large read/write.

Reported-by: S.J. Wang <shengjiu.wang@xxxxxxx>
Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
---
 src/pcm/pcm_dmix.c   | 4 ++--
 src/pcm/pcm_dshare.c | 4 ++--
 src/pcm/pcm_dsnoop.c | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
index d00d53bef604..111fea157228 100644
--- a/src/pcm/pcm_dmix.c
+++ b/src/pcm/pcm_dmix.c
@@ -426,11 +426,11 @@ static int snd_pcm_dmix_sync_ptr(snd_pcm_t *pcm)
 	snd_pcm_direct_t *dmix = pcm->private_data;
 	int err;
 
+	if (dmix->slowptr)
+		snd_pcm_hwsync(dmix->spcm);
 	err = snd_pcm_direct_check_xrun(dmix, pcm);
 	if (err < 0)
 		return err;
-	if (dmix->slowptr)
-		snd_pcm_hwsync(dmix->spcm);
 
 	return snd_pcm_dmix_sync_ptr0(pcm, *dmix->spcm->hw.ptr);
 }
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
index 0ff43a90d270..c46e8d6a53da 100644
--- a/src/pcm/pcm_dshare.c
+++ b/src/pcm/pcm_dshare.c
@@ -201,11 +201,11 @@ static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm)
 	snd_pcm_direct_t *dshare = pcm->private_data;
 	int err;
 
+	if (dshare->slowptr)
+		snd_pcm_hwsync(dshare->spcm);
 	err = snd_pcm_direct_check_xrun(dshare, pcm);
 	if (err < 0)
 		return err;
-	if (dshare->slowptr)
-		snd_pcm_hwsync(dshare->spcm);
 
 	return snd_pcm_dshare_sync_ptr0(pcm, *dshare->spcm->hw.ptr);
 }
diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c
index 729ff447b41f..9abbbef2c1b6 100644
--- a/src/pcm/pcm_dsnoop.c
+++ b/src/pcm/pcm_dsnoop.c
@@ -134,14 +134,14 @@ static int snd_pcm_dsnoop_sync_ptr(snd_pcm_t *pcm)
 	snd_pcm_sframes_t diff;
 	int err;
 
-	err = snd_pcm_direct_check_xrun(dsnoop, pcm);
-	if (err < 0)
-		return err;
 	if (dsnoop->slowptr)
 		snd_pcm_hwsync(dsnoop->spcm);
 	old_slave_hw_ptr = dsnoop->slave_hw_ptr;
 	snoop_timestamp(pcm);
 	slave_hw_ptr = dsnoop->slave_hw_ptr;
+	err = snd_pcm_direct_check_xrun(dsnoop, pcm);
+	if (err < 0)
+		return err;
 	diff = pcm_frame_diff(slave_hw_ptr, old_slave_hw_ptr, dsnoop->slave_boundary);
 	if (diff == 0)		/* fast path */
 		return 0;
-- 
2.34.1




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux