diff options
| author | Jeff Epler <jepler@gmail.com> | 2019-08-06 21:59:16 -0500 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2019-08-06 22:00:31 -0500 |
| commit | 39c64bf83c49571f572f3bc7ad91c10749ae3943 (patch) | |
| tree | 065d1f7016f0cdbd874f64709dd6efeb0d19b1c9 | |
| parent | 8b717955ba198ff38d5122a32f3a3c277bbb3738 (diff) | |
samd: audio_dma_stop: don't free invalid channel
audio_dma_stop can be reached twice in normal usage of AudioOut.
This may bear further investigation, but stop it here, by making the
function check for a previously freed channel number. This also prevents
the event channel from being disabled twice.
The first stop location is from audio_dma_get_playing, when the buffers
are exhausted; the second is from common_hal_audioio_audioout_stop when
checking the 'playing' flag.
| -rw-r--r-- | ports/atmel-samd/audio_dma.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c index 9b38e8bdd..3cb90b86e 100644 --- a/ports/atmel-samd/audio_dma.c +++ b/ports/atmel-samd/audio_dma.c @@ -270,10 +270,13 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma, } void audio_dma_stop(audio_dma_t* dma) { - audio_dma_disable_channel(dma->dma_channel); - disable_event_channel(dma->event_channel); - MP_STATE_PORT(playing_audio)[dma->dma_channel] = NULL; - audio_dma_state[dma->dma_channel] = NULL; + uint8_t channel = dma->dma_channel; + if (channel < AUDIO_DMA_CHANNEL_COUNT) { + audio_dma_disable_channel(channel); + disable_event_channel(dma->event_channel); + MP_STATE_PORT(playing_audio)[channel] = NULL; + audio_dma_state[channel] = NULL; + } dma->dma_channel = AUDIO_DMA_CHANNEL_COUNT; } |
