Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc
[firefly-linux-kernel-4.4.55.git] / sound / core / pcm_native.c
index 3fe99e644eb838a34913f8c6870742e67c227a31..53b5ada8f7c36fd5199366662cc0ce5c5233e66c 100644 (file)
@@ -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;
                }