Skip to content

Commit 0ae81ef

Browse files
tiwaigregkh
authored andcommitted
ALSA: pcm: Add stream lock during PCM reset ioctl operations
commit 1f68915 upstream. snd_pcm_reset() is a non-atomic operation, and it's allowed to run during the PCM stream running. It implies that the manipulation of hw_ptr and other parameters might be racy. This patch adds the PCM stream lock at appropriate places in snd_pcm_*_reset() actions for covering that. Cc: <stable@vger.kernel.org> Reviewed-by: Jaroslav Kysela <perex@perex.cz> Link: https://lore.kernel.org/r/20220322171325.4355-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b560d67 commit 0ae81ef

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

sound/core/pcm_native.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,22 +1850,26 @@ static int snd_pcm_do_reset(struct snd_pcm_substream *substream,
18501850
int err = snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL);
18511851
if (err < 0)
18521852
return err;
1853+
snd_pcm_stream_lock_irq(substream);
18531854
runtime->hw_ptr_base = 0;
18541855
runtime->hw_ptr_interrupt = runtime->status->hw_ptr -
18551856
runtime->status->hw_ptr % runtime->period_size;
18561857
runtime->silence_start = runtime->status->hw_ptr;
18571858
runtime->silence_filled = 0;
1859+
snd_pcm_stream_unlock_irq(substream);
18581860
return 0;
18591861
}
18601862

18611863
static void snd_pcm_post_reset(struct snd_pcm_substream *substream,
18621864
snd_pcm_state_t state)
18631865
{
18641866
struct snd_pcm_runtime *runtime = substream->runtime;
1867+
snd_pcm_stream_lock_irq(substream);
18651868
runtime->control->appl_ptr = runtime->status->hw_ptr;
18661869
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
18671870
runtime->silence_size > 0)
18681871
snd_pcm_playback_silence(substream, ULONG_MAX);
1872+
snd_pcm_stream_unlock_irq(substream);
18691873
}
18701874

18711875
static const struct action_ops snd_pcm_action_reset = {

0 commit comments

Comments
 (0)