From 3da8257a63a266c4d2432985911c2090cf044a86 Mon Sep 17 00:00:00 2001 From: Curtis Malainey Date: Tue, 27 Oct 2020 19:49:47 -0700 Subject: [PATCH] dma-trace: free buffer on error We are leaking memory if the host sends bad messages to the firmware since we are not freeing the buffer. Signed-off-by: Curtis Malainey --- src/trace/dma-trace.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/trace/dma-trace.c b/src/trace/dma-trace.c index 61c5acff0147..d9822ea395d1 100644 --- a/src/trace/dma-trace.c +++ b/src/trace/dma-trace.c @@ -215,6 +215,19 @@ static int dma_trace_buffer_init(struct dma_trace_data *d) return 0; } +static void dma_trace_buffer_free(struct dma_trace_data *d) +{ + struct dma_trace_buf *buffer = &d->dmatb; + unsigned int flags; + + spin_lock_irq(&d->lock, flags); + + rfree(buffer->addr); + memset(buffer, 0, sizeof(*buffer)); + + spin_unlock_irq(&d->lock, flags); +} + #if CONFIG_DMA_GW static int dma_trace_start(struct dma_trace_data *d) @@ -349,6 +362,9 @@ int dma_trace_enable(struct dma_trace_data *d) schedule_task(&d->dmat_work, DMA_TRACE_PERIOD, DMA_TRACE_PERIOD); out: + if (err < 0) + dma_trace_buffer_free(d); + platform_shared_commit(d, sizeof(*d)); return err;