pcm: direct: Check xrun/suspend before the slave hwptr update

The xrun/suspend may happen at any time and we should check it right
after the slave hwptr update (but before the actual sync_ptr update in
direct pcm side).  Otherwise the hwptr value may be screwed and get
unexpected large read/write.

Reported-by: S.J. Wang <shengjiu.wang@nxp.com>
Acked-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2022-03-10 09:24:12 +01:00
parent 3577a7a26b
commit bb9f258e19
3 changed files with 13 additions and 9 deletions

View file

@ -199,15 +199,17 @@ static int snd_pcm_dshare_sync_ptr0(snd_pcm_t *pcm, snd_pcm_uframes_t slave_hw_p
static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm)
{
snd_pcm_direct_t *dshare = pcm->private_data;
snd_pcm_uframes_t slave_hw_ptr;
int err;
if (dshare->slowptr)
snd_pcm_hwsync(dshare->spcm);
slave_hw_ptr = *dshare->spcm->hw.ptr;
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);
return snd_pcm_dshare_sync_ptr0(pcm, slave_hw_ptr);
}
/*