Skip to content

Commit

Permalink
ASoC: SOF: pcm: fix error handling in pcm_new
Browse files Browse the repository at this point in the history
The error flow in pcm_new was completely broken, make sure the page
tables are released.

The pre-allocated DMA buffer is not released since it's a task the
ALSA core will do for us. Added comment of the intent so that people
looking for balanced memory allocations understand this is not an
omission.

Signed-off-by: Pierre-Louis Bossart <[email protected]>
  • Loading branch information
plbossart committed Nov 30, 2018
1 parent 8945d3d commit 9374795
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions sound/soc/sof/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ static int sof_pcm_new(struct snd_soc_pcm_runtime *rtd)
if (ret < 0) {
dev_err(sdev->dev, "error: can't alloc page table for %s %d\n",
caps->name, ret);
return ret;
goto free_playback_dma_buffer;
}

capture:
Expand All @@ -547,8 +547,7 @@ static int sof_pcm_new(struct snd_soc_pcm_runtime *rtd)
dev_err(sdev->dev, "error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n",
caps->buffer_size_min, caps->buffer_size_max,
caps->name, ret);
snd_dma_free_pages(&spcm->stream[stream].page_table);
return ret;
goto free_playback_tables;
}

/* allocate capture page table buffer */
Expand All @@ -557,13 +556,24 @@ static int sof_pcm_new(struct snd_soc_pcm_runtime *rtd)
if (ret < 0) {
dev_err(sdev->dev, "error: can't alloc page table for %s %d\n",
caps->name, ret);
snd_dma_free_pages(&spcm->stream[stream].page_table);
return ret;
goto free_playback_tables;
}

/* TODO: assign channel maps from topology */

return ret;

free_playback_tables:
if (spcm->pcm.playback)
snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].page_table);

free_playback_dma_buffer:
/*
* no need to explicitly release preallocated memory,
* snd_pcm_lib_preallocate_free_for_all() is called by the core
*/

return ret;
}

static void sof_pcm_free(struct snd_pcm *pcm)
Expand All @@ -588,6 +598,10 @@ static void sof_pcm_free(struct snd_pcm *pcm)
if (spcm->pcm.capture)
snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_CAPTURE].page_table);

/*
* no need to explicitly release preallocated memory,
* snd_pcm_lib_preallocate_free_for_all() is called by the core
*/
}

/* fixup the BE DAI link to match any values from topology */
Expand Down

0 comments on commit 9374795

Please sign in to comment.