Skip to content

Commit 6a7db25

Browse files
TE-N-ShengjiuWangtiwai
authored andcommitted
ALSA: dmaengine_pcm: terminate dmaengine before synchronize
When dmaengine supports pause function, in suspend state, dmaengine_pause() is called instead of dmaengine_terminate_async(), In end of playback stream, the runtime->state will go to SNDRV_PCM_STATE_DRAINING, if system suspend & resume happen at this time, application will not resume playback stream, the stream will be closed directly, the dmaengine_terminate_async() will not be called before the dmaengine_synchronize(), which violates the call sequence for dmaengine_synchronize(). This behavior also happens for capture streams, but there is no SNDRV_PCM_STATE_DRAINING state for capture. So use dmaengine_tx_status() to check the DMA status if the status is DMA_PAUSED, then call dmaengine_terminate_async() to terminate dmaengine before dmaengine_synchronize(). Signed-off-by: Shengjiu Wang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 1d091a9 commit 6a7db25

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sound/core/pcm_dmaengine.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan);
358358
int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
359359
{
360360
struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
361+
struct dma_tx_state state;
362+
enum dma_status status;
363+
364+
status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state);
365+
if (status == DMA_PAUSED)
366+
dmaengine_terminate_async(prtd->dma_chan);
361367

362368
dmaengine_synchronize(prtd->dma_chan);
363369
kfree(prtd);
@@ -378,6 +384,12 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close);
378384
int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream)
379385
{
380386
struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
387+
struct dma_tx_state state;
388+
enum dma_status status;
389+
390+
status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state);
391+
if (status == DMA_PAUSED)
392+
dmaengine_terminate_async(prtd->dma_chan);
381393

382394
dmaengine_synchronize(prtd->dma_chan);
383395
dma_release_channel(prtd->dma_chan);

0 commit comments

Comments
 (0)