Skip to content

Commit b35aba3

Browse files
lrgirdwolgirdwood
authored andcommitted
xtos: heap: check all SYS_ allocations
Previously with xtos config the linker would reserve a guaranteed heap for init system allocations that were all guaranteed to succeed. These allocations never failed with Zephyr as they were all done at early boot. Be more mindful and check in the unlikely result of a failure. e.g. a Kconfig with heapsize == 0 Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 5821682 commit b35aba3

File tree

26 files changed

+186
-14
lines changed

26 files changed

+186
-14
lines changed

src/audio/base_fw_intel.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ __cold static int basefw_mem_state_info(uint32_t *data_offset, char *data)
183183
size = ALIGN(size, 4);
184184
/* size is also saved as tuple length */
185185
tuple_data = rballoc(SOF_MEM_FLAG_USER, size);
186+
if (!tuple_data) {
187+
LOG_ERR("basefw_mem_state_info(): allocation failed");
188+
return IPC4_ERROR_INVALID_PARAM;
189+
}
186190

187191
/* save memory info in data array since info length is variable */
188192
index = 0;

src/drivers/imx/ipc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ int platform_ipc_init(struct ipc *ipc)
202202
/* allocate page table buffer */
203203
iipc->dh_buffer.page_table = rzalloc(SOF_MEM_FLAG_USER,
204204
PLATFORM_PAGE_TABLE_SIZE);
205-
if (iipc->dh_buffer.page_table)
206-
bzero(iipc->dh_buffer.page_table, PLATFORM_PAGE_TABLE_SIZE);
205+
if (!iipc->dh_buffer.page_table)
206+
sof_panic(SOF_IPC_PANIC_IPC);
207+
bzero(iipc->dh_buffer.page_table, PLATFORM_PAGE_TABLE_SIZE);
207208
#if CONFIG_ZEPHYR_NATIVE_DRIVERS
208209
iipc->dh_buffer.dmac = sof_dma_get(SOF_DMA_DIR_HMEM_TO_LMEM, 0, SOF_DMA_DEV_HOST,
209210
SOF_DMA_ACCESS_SHARED);

src/drivers/interrupt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ int interrupt_cascade_register(const struct irq_cascade_tmpl *tmpl)
7474
}
7575

7676
*cascade = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(**cascade));
77+
if (!*cascade) {
78+
ret = -ENOMEM;
79+
tr_err(&irq_tr, "cascading IRQ controller allocation failed!");
80+
goto unlock;
81+
}
7782

7883
k_spinlock_init(&(*cascade)->lock);
7984

src/drivers/mediatek/mt818x/ipc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ int platform_ipc_init(struct ipc *ipc)
128128
struct ipc_data *iipc;
129129

130130
iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc));
131+
if (!iipc) {
132+
tr_err(&ipc_tr, "Unable to allocate memory for IPC data");
133+
sof_panic(SOF_IPC_PANIC_IPC);
134+
}
131135
ipc_set_drvdata(ipc, iipc);
132136
#else
133137
ipc_set_drvdata(ipc, NULL);
@@ -143,6 +147,10 @@ int platform_ipc_init(struct ipc *ipc)
143147
/* allocate page table buffer */
144148
iipc->dh_buffer.page_table =
145149
rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE);
150+
if (!iipc->dh_buffer.page_table) {
151+
tr_err(&ipc_tr, "Unable to allocate host page table buffer");
152+
sof_panic(SOF_IPC_PANIC_IPC);
153+
}
146154

147155
iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED);
148156
if (!iipc->dh_buffer.dmac) {

src/drivers/mediatek/mt8195/ipc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ int platform_ipc_init(struct ipc *ipc)
127127
struct ipc_data *iipc;
128128

129129
iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc));
130+
if (!iipc) {
131+
tr_err(&ipc_tr, "Unable to allocate memory for IPC data");
132+
sof_panic(SOF_IPC_PANIC_IPC);
133+
}
130134
ipc_set_drvdata(ipc, iipc);
131135
#else
132136
ipc_set_drvdata(ipc, NULL);
@@ -141,6 +145,10 @@ int platform_ipc_init(struct ipc *ipc)
141145
/* allocate page table buffer */
142146
iipc->dh_buffer.page_table =
143147
rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE);
148+
if (!iipc->dh_buffer.page_table) {
149+
tr_err(&ipc_tr, "Unable to allocate host page table buffer");
150+
sof_panic(SOF_IPC_PANIC_IPC);
151+
}
144152

145153
iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED);
146154
if (!iipc->dh_buffer.dmac) {

src/drivers/mediatek/mt8196/ipc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ int platform_ipc_init(struct ipc *ipc)
127127
struct ipc_data *iipc;
128128

129129
iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc));
130+
if (!iipc) {
131+
tr_err(&ipc_tr, "Unable to allocate memory for IPC data");
132+
sof_panic(SOF_IPC_PANIC_IPC);
133+
}
130134
ipc_set_drvdata(ipc, iipc);
131135
#else
132136
ipc_set_drvdata(ipc, NULL);
@@ -142,6 +146,10 @@ int platform_ipc_init(struct ipc *ipc)
142146
/* allocate page table buffer */
143147
iipc->dh_buffer.page_table =
144148
rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE);
149+
if (!iipc->dh_buffer.page_table) {
150+
tr_err(&ipc_tr, "Unable to allocate host page table buffer");
151+
sof_panic(SOF_IPC_PANIC_IPC);
152+
}
145153

146154
iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED);
147155
if (!iipc->dh_buffer.dmac) {

src/drivers/mediatek/mt8365/ipc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int platform_ipc_init(struct ipc *ipc)
143143
iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc));
144144
if (!iipc) {
145145
tr_err(&ipc_tr, "Unable to allocate IPC private data");
146-
return -ENOMEM;
146+
sof_panic(SOF_IPC_PANIC_IPC);
147147
}
148148
ipc_set_drvdata(ipc, iipc);
149149
#else
@@ -159,6 +159,10 @@ int platform_ipc_init(struct ipc *ipc)
159159
/* allocate page table buffer */
160160
iipc->dh_buffer.page_table =
161161
rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE);
162+
if (!iipc->dh_buffer.page_table) {
163+
tr_err(&ipc_tr, "Unable to allocate host page table buffer");
164+
sof_panic(SOF_IPC_PANIC_IPC);
165+
}
162166

163167
iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED);
164168
if (!iipc->dh_buffer.dmac) {

src/include/sof/schedule/ll_schedule_domain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ static inline struct ll_schedule_domain *domain_init
9999
struct ll_schedule_domain *domain;
100100

101101
domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*domain));
102+
if (!domain)
103+
return NULL;
102104
domain->type = type;
103105
domain->clk = clk;
104106
domain->synchronous = synchronous;

src/ipc/ipc-common.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,17 @@ __cold int ipc_init(struct sof *sof)
293293

294294
/* init ipc data */
295295
sof->ipc = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->ipc));
296+
if (!sof->ipc) {
297+
tr_err(&ipc_tr, "Unable to allocate IPC data");
298+
return -ENOMEM;
299+
}
296300
sof->ipc->comp_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
297301
SOF_IPC_MSG_MAX_SIZE);
302+
if (!sof->ipc->comp_data) {
303+
tr_err(&ipc_tr, "Unable to allocate IPC component data");
304+
rfree(sof->ipc);
305+
return -ENOMEM;
306+
}
298307

299308
k_spinlock_init(&sof->ipc->lock);
300309
list_init(&sof->ipc->msg_list);

src/lib/dai.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ __cold static struct dai_group_list *dai_group_list_get(int core_id)
4343
if (!group_list) {
4444
group_list = rzalloc(SOF_MEM_FLAG_USER,
4545
sizeof(*group_list));
46+
if (!group_list) {
47+
tr_err(&dai_tr, "dai_group_list_get(): failed to allocate group_list for core %d",
48+
core_id);
49+
return NULL;
50+
}
4651

4752
groups[core_id] = group_list;
4853
list_init(&group_list->list);
@@ -54,12 +59,19 @@ __cold static struct dai_group_list *dai_group_list_get(int core_id)
5459
__cold static struct dai_group *dai_group_find(uint32_t group_id)
5560
{
5661
struct list_item *dai_groups;
62+
struct dai_group_list *group_list;
5763
struct list_item *group_item;
5864
struct dai_group *group = NULL;
5965

6066
assert_can_be_cold();
6167

62-
dai_groups = &dai_group_list_get(cpu_get_id())->list;
68+
group_list = dai_group_list_get(cpu_get_id());
69+
if (!group_list) {
70+
tr_err(&dai_tr, "dai_group_find(): failed to get group_list for core %d",
71+
cpu_get_id());
72+
return NULL;
73+
}
74+
dai_groups = &group_list->list;
6375

6476
list_for_item(group_item, dai_groups) {
6577
group = container_of(group_item, struct dai_group, list);
@@ -75,13 +87,24 @@ __cold static struct dai_group *dai_group_find(uint32_t group_id)
7587

7688
__cold static struct dai_group *dai_group_alloc(void)
7789
{
78-
struct list_item *dai_groups = &dai_group_list_get(cpu_get_id())->list;
90+
struct dai_group_list *group_list = dai_group_list_get(cpu_get_id());
91+
struct list_item *dai_groups;
7992
struct dai_group *group;
8093

8194
assert_can_be_cold();
95+
if (!group_list) {
96+
tr_err(&dai_tr, "dai_group_alloc(): failed to get group_list for core %d",
97+
cpu_get_id());
98+
return NULL;
99+
}
100+
dai_groups = &group_list->list;
82101

83102
group = rzalloc(SOF_MEM_FLAG_USER,
84103
sizeof(*group));
104+
if (!group) {
105+
tr_err(&dai_tr, "dai_group_alloc(): failed to allocate dai group");
106+
return NULL;
107+
}
85108

86109
list_item_prepend(&group->list, dai_groups);
87110

0 commit comments

Comments
 (0)