From: Takashi Iwai Date: Mon, 21 May 2012 09:59:57 +0000 (+0200) Subject: ALSA: pcm - Add proper state checks to snd_pcm_drain() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4f7c39dc557cabdbc932ae83432cc225c480133c;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git ALSA: pcm - Add proper state checks to snd_pcm_drain() The handling for some PCM states is missing for snd_pcm_drain(). At least, XRUN streams should be simply dropped to SETUP, and a few initial invalid states should be rejected. Signed-off-by: Takashi Iwai --- diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 3fe99e644eb8..53b5ada8f7c3 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1360,7 +1360,14 @@ static int snd_pcm_prepare(struct snd_pcm_substream *substream, static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, int state) { - substream->runtime->trigger_master = substream; + struct snd_pcm_runtime *runtime = substream->runtime; + switch (runtime->status->state) { + case SNDRV_PCM_STATE_OPEN: + case SNDRV_PCM_STATE_DISCONNECTED: + case SNDRV_PCM_STATE_SUSPENDED: + return -EBADFD; + } + runtime->trigger_master = substream; return 0; } @@ -1379,6 +1386,9 @@ static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, int state) case SNDRV_PCM_STATE_RUNNING: runtime->status->state = SNDRV_PCM_STATE_DRAINING; break; + case SNDRV_PCM_STATE_XRUN: + runtime->status->state = SNDRV_PCM_STATE_SETUP; + break; default: break; }