Skip to content

Commit 1f68915

Browse files
committed
ALSA: pcm: Add stream lock during PCM reset ioctl operations
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>
1 parent 69534c4 commit 1f68915

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
@@ -1864,22 +1864,26 @@ static int snd_pcm_do_reset(struct snd_pcm_substream *substream,
18641864
int err = snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL);
18651865
if (err < 0)
18661866
return err;
1867+
snd_pcm_stream_lock_irq(substream);
18671868
runtime->hw_ptr_base = 0;
18681869
runtime->hw_ptr_interrupt = runtime->status->hw_ptr -
18691870
runtime->status->hw_ptr % runtime->period_size;
18701871
runtime->silence_start = runtime->status->hw_ptr;
18711872
runtime->silence_filled = 0;
1873+
snd_pcm_stream_unlock_irq(substream);
18721874
return 0;
18731875
}
18741876

18751877
static void snd_pcm_post_reset(struct snd_pcm_substream *substream,
18761878
snd_pcm_state_t state)
18771879
{
18781880
struct snd_pcm_runtime *runtime = substream->runtime;
1881+
snd_pcm_stream_lock_irq(substream);
18791882
runtime->control->appl_ptr = runtime->status->hw_ptr;
18801883
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
18811884
runtime->silence_size > 0)
18821885
snd_pcm_playback_silence(substream, ULONG_MAX);
1886+
snd_pcm_stream_unlock_irq(substream);
18831887
}
18841888

18851889
static const struct action_ops snd_pcm_action_reset = {

0 commit comments

Comments
 (0)