Skip to content

Commit

Permalink
ALSA: pcm - Add proper state checks to snd_pcm_drain()
Browse files Browse the repository at this point in the history
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 <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed May 21, 2012
1 parent d4c6983 commit 4f7c39d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sound/core/pcm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 4f7c39d

Please sign in to comment.