1456 snd_pcm_stream_lock_irq(substream);
1457
1458 if (substream->runtime->status->state == SNDRV_PCM_STATE_PAUSED)
1459 snd_pcm_pause(substream, 0);
1460
1461
1462 result = snd_pcm_action(&snd_pcm_action_drain_init, substream, 0);
1463 if (result < 0) {
1464 snd_pcm_stream_unlock_irq(substream);
1465 goto _error;
1466 }
1467
1468 for (;;) {
1469 long tout;
1470 if (signal_pending(current)) {
1471 result = -ERESTARTSYS;
1472 break;
1473 }
1474
1475 for (i = 0; i < num_drecs; i++) {
1476 runtime = drec[i].substream->runtime;
1477 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING)
1478 break;
1479 }
1480 if (i == num_drecs)
1481 break;
1482
1483 set_current_state(TASK_INTERRUPTIBLE);
1484 snd_pcm_stream_unlock_irq(substream);
1485 snd_power_unlock(card);
1486 tout = schedule_timeout(10 * HZ);
1487 snd_power_lock(card);
1488 snd_pcm_stream_lock_irq(substream);
1489 if (tout == 0) {
1490 if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED)
1491 result = -ESTRPIPE;
1492 else {
1493 snd_printd("playback drain error (DMA or IRQ trouble?)\n");
1494 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
1495 result = -EIO;
1496 }