dma-trace: Fix memory leak with buffer allocation on dtrace re-config

Do not attempt to allocate the dtrace buffer again if it has been already
allocated.
This only possible if we are re-configuring the dtrace which implies that
we also must have the DMA channel.

In such case, skip the allocation and do a re-init of the buffer after the
DMA channel has been stopped.

Reported-by: Keyon Jie <yang.jie@linux.intel.com>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
This commit is contained in:
Peter Ujfalusi 2021-10-15 09:23:43 +03:00 committed by Liam Girdwood
parent fbab621c9b
commit e11673258c
1 changed files with 16 additions and 1 deletions

View File

@ -226,6 +226,17 @@ static int dma_trace_buffer_init(struct dma_trace_data *d)
uint32_t addr_align;
int err;
/*
* Keep the existing dtrace buffer to avoid memory leak, unlikely to
* happen if host correctly using the dma_trace_disable().
*
* The buffer can not be freed up here as it is likely in use.
* The (re-)initialization will happen in dma_trace_start() when it is
* safe to do (the DMA is stopped)
*/
if (dma_trace_initialized(d))
return 0;
if (!d || !d->dc.dmac) {
mtrace_printf(LOG_LEVEL_ERROR,
"%s failed: no DMAC!", __func__);
@ -344,6 +355,10 @@ static int dma_trace_start(struct dma_trace_data *d)
if (err < 0)
return err;
/* Reset host buffer information as host is re-configuring dtrace */
d->old_host_offset = 0;
d->posn.host_offset = 0;
d->active_stream_tag = d->stream_tag;
/* size of every trace record */
@ -446,7 +461,7 @@ int dma_trace_enable(struct dma_trace_data *d)
{
int err;
/* Allocate and initialize the dma trace buffer */
/* Allocate and initialize the dma trace buffer if needed */
err = dma_trace_buffer_init(d);
if (err < 0)
return err;