Skip to content

Commit 89ec377

Browse files
keyonjielgirdwood
authored andcommitted
dma-trace: add check to avoid dereference from NULL
The DMA trace is not necessary enabled so the trace_data could be NULL, add check to avoid dereference from NULL pointer and panics. Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
1 parent a226f0b commit 89ec377

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/ipc/dma-copy.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ int dma_copy_to_host_nowait(struct dma_copy *dc, struct dma_sg_config *host_sg,
6464
{
6565
int ret;
6666

67+
/* return if DMA channel is not get yet */
68+
if (!dc->chan)
69+
return -EINVAL;
70+
6771
/* tell gateway to copy */
6872
ret = dma_copy(dc->chan, size, 0);
6973
if (ret < 0)
@@ -85,6 +89,10 @@ int dma_copy_to_host_nowait(struct dma_copy *dc, struct dma_sg_config *host_sg,
8589
int32_t err;
8690
int32_t offset = host_offset;
8791

92+
/* return if DMA channel is not get yet */
93+
if (!dc->chan)
94+
return -EINVAL;
95+
8896
if (size <= 0)
8997
return 0;
9098

src/platform/intel/cavs/platform.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,9 @@ int platform_init(struct sof *sof)
524524
#elif CONFIG_TRACE
525525
/* Initialize DMA for Trace*/
526526
trace_point(TRACE_BOOT_PLATFORM_DMA_TRACE);
527-
dma_trace_init_complete(sof->dmat);
527+
ret = dma_trace_init_complete(sof->dmat);
528+
if (ret < 0)
529+
return ret;
528530
#endif
529531

530532
/* show heap status */

src/trace/dma-trace.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,8 @@ void dma_trace_on(void)
476476
{
477477
struct dma_trace_data *trace_data = dma_trace_data_get();
478478

479-
if (trace_data->enabled) {
479+
if (!trace_data || trace_data->enabled)
480480
return;
481-
}
482481

483482
trace_data->enabled = 1;
484483
schedule_task(&trace_data->dmat_work, DMA_TRACE_PERIOD,
@@ -490,9 +489,8 @@ void dma_trace_off(void)
490489
{
491490
struct dma_trace_data *trace_data = dma_trace_data_get();
492491

493-
if (!trace_data->enabled) {
492+
if (!trace_data || !trace_data->enabled)
494493
return;
495-
}
496494

497495
schedule_task_cancel(&trace_data->dmat_work);
498496
trace_data->enabled = 0;

src/trace/trace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ void trace_log_unfiltered(bool send_atomic, const void *log_entry, const struct
272272
struct trace *trace = trace_get();
273273
va_list vl;
274274

275-
if (!trace->enable) {
275+
if (!trace || !trace->enable)
276276
return;
277-
}
278277

279278
va_start(vl, arg_count);
280279
vatrace_log(send_atomic, (uint32_t)log_entry, ctx, lvl, id_1, id_2, arg_count, vl);

0 commit comments

Comments
 (0)