Skip to content

Commit 337b7b0

Browse files
committed
ALSA: pcm_dmaengine: Unify two close functions
Both snd_dmaengine_pcm_close() and snd_dmaengine_pcm_close_release_chan() are almost identical except for a call of dma_release_channel() in the latter. For code simplification, unify them internally. Just a code refactoring, and no functional changes. Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 6f7dae6 commit 337b7b0

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

sound/core/pcm_dmaengine.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,8 @@ int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
349349
}
350350
EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan);
351351

352-
/**
353-
* snd_dmaengine_pcm_close - Close a dmaengine based PCM substream
354-
* @substream: PCM substream
355-
*
356-
* Return: 0 on success, a negative error code otherwise
357-
*/
358-
int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
352+
static void __snd_dmaengine_pcm_close(struct snd_pcm_substream *substream,
353+
bool release_channel)
359354
{
360355
struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
361356
struct dma_tx_state state;
@@ -366,8 +361,20 @@ int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
366361
dmaengine_terminate_async(prtd->dma_chan);
367362

368363
dmaengine_synchronize(prtd->dma_chan);
364+
if (release_channel)
365+
dma_release_channel(prtd->dma_chan);
369366
kfree(prtd);
367+
}
370368

369+
/**
370+
* snd_dmaengine_pcm_close - Close a dmaengine based PCM substream
371+
* @substream: PCM substream
372+
*
373+
* Return: 0 on success, a negative error code otherwise
374+
*/
375+
int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
376+
{
377+
__snd_dmaengine_pcm_close(substream, false);
371378
return 0;
372379
}
373380
EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close);
@@ -383,18 +390,7 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close);
383390
*/
384391
int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream)
385392
{
386-
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);
393-
394-
dmaengine_synchronize(prtd->dma_chan);
395-
dma_release_channel(prtd->dma_chan);
396-
kfree(prtd);
397-
393+
__snd_dmaengine_pcm_close(substream, true);
398394
return 0;
399395
}
400396
EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close_release_chan);

0 commit comments

Comments
 (0)