OSDN Git Service

PCM: snd_pcm_xxxx_drain() maybe blocked after suspend and resume
authorShengjiu Wang <shengjiu.wang@freescale.com>
Fri, 12 Jun 2015 08:15:08 +0000 (16:15 +0800)
committerTakashi Iwai <tiwai@suse.de>
Fri, 12 Jun 2015 10:39:24 +0000 (12:39 +0200)
After suspend and resume, the alsa driver is stopped. But if alsa-lib run
into snd_pcm_xxxx_drain(), it need to wait avail >= pcm->stop_threshold,
otherwise, it will not exit the loop, so finally it is blocked at poll() of
snd_pcm_wait_nocheck(pcm, -1).
This patch is to add state check after snd_pcm_wait_nocheck(pcm, -1), if
the state is SND_PCM_STATE_SUSPENDED, then return error.

Signed-off-by: Shengjiu Wang <shengjiu.wang@freescale.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm_dmix.c
src/pcm/pcm_dshare.c

index 4acbaf0..58e4975 100644 (file)
@@ -617,6 +617,13 @@ static int snd_pcm_dmix_drain(snd_pcm_t *pcm)
        snd_pcm_uframes_t stop_threshold;
        int err;
 
+       switch (snd_pcm_state(dmix->spcm)) {
+       case SND_PCM_STATE_SUSPENDED:
+               return -ESTRPIPE;
+       default:
+               break;
+       }
+
        if (dmix->state == SND_PCM_STATE_OPEN)
                return -EBADFD;
        if (pcm->mode & SND_PCM_NONBLOCK)
@@ -649,6 +656,13 @@ static int snd_pcm_dmix_drain(snd_pcm_t *pcm)
                        snd_pcm_dmix_sync_area(pcm);
                        snd_pcm_wait_nocheck(pcm, -1);
                        snd_pcm_direct_clear_timer_queue(dmix); /* force poll to wait */
+
+                       switch (snd_pcm_state(dmix->spcm)) {
+                       case SND_PCM_STATE_SUSPENDED:
+                               return -ESTRPIPE;
+                       default:
+                               break;
+                       }
                }
        } while (dmix->state == SND_PCM_STATE_DRAINING);
        pcm->stop_threshold = stop_threshold;
index b51758f..02370dc 100644 (file)
@@ -368,6 +368,13 @@ static int snd_pcm_dshare_drain(snd_pcm_t *pcm)
        snd_pcm_uframes_t stop_threshold;
        int err;
 
+       switch (snd_pcm_state(dshare->spcm)) {
+       case SND_PCM_STATE_SUSPENDED:
+               return -ESTRPIPE;
+       default:
+               break;
+       }
+
        if (dshare->state == SND_PCM_STATE_OPEN)
                return -EBADFD;
        if (pcm->mode & SND_PCM_NONBLOCK)
@@ -400,6 +407,13 @@ static int snd_pcm_dshare_drain(snd_pcm_t *pcm)
                        snd_pcm_dshare_sync_area(pcm);
                        snd_pcm_wait_nocheck(pcm, -1);
                        snd_pcm_direct_clear_timer_queue(dshare); /* force poll to wait */
+
+                       switch (snd_pcm_state(dshare->spcm)) {
+                       case SND_PCM_STATE_SUSPENDED:
+                               return -ESTRPIPE;
+                       default:
+                               break;
+                       }
                }
        } while (dshare->state == SND_PCM_STATE_DRAINING);
        pcm->stop_threshold = stop_threshold;