Skip to content

Commit 079558d

Browse files
authored
Merge pull request #495 from mmaka1/drv-alloc-fix
alloc: fixed memory leaks in dw-dma
2 parents 98f73a8 + c7574ef commit 079558d

6 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/drivers/intel/cavs/dmic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ static int dmic_probe(struct dai *dai)
14541454
pm_runtime_get_sync(DMIC_CLK, dai->index);
14551455

14561456
/* allocate private data */
1457-
dmic = rzalloc(RZONE_SYS | RZONE_FLAG_UNCACHED, SOF_MEM_CAPS_RAM,
1457+
dmic = rzalloc(RZONE_RUNTIME | RZONE_FLAG_UNCACHED, SOF_MEM_CAPS_RAM,
14581458
sizeof(*dmic));
14591459
if (!dmic) {
14601460
trace_dmic_error("eap");

src/drivers/intel/cavs/hda-dma.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,12 @@ static int hda_dma_probe(struct dma *dma)
614614
return -EEXIST; /* already created */
615615

616616
/* allocate private data */
617-
hda_pdata = rzalloc(RZONE_SYS | RZONE_FLAG_UNCACHED, SOF_MEM_CAPS_RAM,
618-
sizeof(*hda_pdata));
617+
hda_pdata = rzalloc(RZONE_RUNTIME | RZONE_FLAG_UNCACHED,
618+
SOF_MEM_CAPS_RAM, sizeof(*hda_pdata));
619+
if (!hda_pdata) {
620+
trace_error(TRACE_CLASS_DMA, "alloc failed");
621+
return -ENOMEM;
622+
}
619623
dma_set_drvdata(dma, hda_pdata);
620624

621625
/* init channel status */

src/drivers/intel/cavs/ssp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,12 @@ static int ssp_probe(struct dai *dai)
875875
pm_runtime_get_sync(SSP_CLK, dai->index);
876876

877877
/* allocate private data */
878-
ssp = rzalloc(RZONE_SYS | RZONE_FLAG_UNCACHED, SOF_MEM_CAPS_RAM,
878+
ssp = rzalloc(RZONE_RUNTIME | RZONE_FLAG_UNCACHED, SOF_MEM_CAPS_RAM,
879879
sizeof(*ssp));
880+
if (!ssp) {
881+
trace_error(TRACE_CLASS_DAI, "alloc failed");
882+
return -ENOMEM;
883+
}
880884
dai_set_drvdata(dai, ssp);
881885

882886
ssp->state[DAI_DIR_PLAYBACK] = COMP_STATE_READY;

src/drivers/intel/dw-dma.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,8 @@ static inline void dw_dma_interrupt_register(struct dma *dma, int channel)
11361136
uint32_t irq = dma_irq(dma, cpu_get_id()) +
11371137
(channel << SOF_IRQ_BIT_SHIFT);
11381138

1139+
trace_event(TRACE_CLASS_DMA, "dw-dma-int-register");
1140+
11391141
interrupt_register(irq, IRQ_AUTO_UNMASK, dw_dma_irq_handler,
11401142
&p->chan[channel].id);
11411143
interrupt_enable(irq);
@@ -1278,8 +1280,12 @@ static int dw_dma_probe(struct dma *dma)
12781280
pm_runtime_get_sync(DW_DMAC_CLK, dma->plat_data.id);
12791281

12801282
/* allocate private data */
1281-
dw_pdata = rzalloc(RZONE_SYS | RZONE_FLAG_UNCACHED, SOF_MEM_CAPS_RAM,
1282-
sizeof(*dw_pdata));
1283+
dw_pdata = rzalloc(RZONE_RUNTIME | RZONE_FLAG_UNCACHED,
1284+
SOF_MEM_CAPS_RAM, sizeof(*dw_pdata));
1285+
if (!dw_pdata) {
1286+
trace_error(TRACE_CLASS_DMA, "alloc failed");
1287+
return -ENOMEM;
1288+
}
12831289
dma_set_drvdata(dma, dw_pdata);
12841290

12851291
spinlock_init(&dma->lock);

src/lib/alloc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ static void *rmalloc_sys(int zone, int core, size_t bytes)
127127

128128
/* always succeeds or panics */
129129
if (alignment + bytes > cpu_heap->info.free) {
130-
trace_mem_error("eM1");
130+
trace_error(TRACE_CLASS_MEM,
131+
"rmalloc-sys eM1 zone %x core %d bytes %d",
132+
zone, core, bytes);
131133
panic(SOF_IPC_PANIC_MEM);
132134
}
133135
cpu_heap->info.used += alignment;
@@ -419,9 +421,9 @@ static void *rmalloc_runtime(int zone, uint32_t caps, size_t bytes)
419421
return ptr;
420422

421423
error:
422-
trace_mem_error("eMm");
423-
trace_error_value(bytes);
424-
trace_error_value(caps);
424+
trace_error(TRACE_CLASS_MEM,
425+
"rmalloc-runtime eMm zone %d caps %x bytes %d",
426+
zone, caps, bytes);
425427
return NULL;
426428
}
427429

src/lib/interrupt.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ static int irq_register_child(struct irq_desc *parent, int irq, int unmask,
5555

5656
spin_lock(&parent->lock);
5757

58-
/* init child */
59-
child = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM,
58+
/* init child from run-time, may be registered and unregistered
59+
* many times at run-time
60+
*/
61+
child = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM,
6062
sizeof(struct irq_desc));
6163
if (!child) {
6264
ret = -ENOMEM;
@@ -102,6 +104,7 @@ static void irq_unregister_child(struct irq_desc *parent, int irq)
102104
if (SOF_IRQ_ID(irq) == child->id) {
103105
list_item_del(&child->irq_list);
104106
parent->num_children--;
107+
rfree(child);
105108
}
106109
}
107110

0 commit comments

Comments
 (0)