Skip to content

Commit 88c0d66

Browse files
committed
module-adapter: move mod_alloc() allocations to the module heap
Move mod_alloc() allocations, including the container pool, to the module local heap. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent f6dac5f commit 88c0d66

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/audio/module_adapter/module/generic.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,20 @@ struct container_chunk {
131131
static struct module_resource *container_get(struct processing_module *mod)
132132
{
133133
struct module_resources *res = &mod->priv.resources;
134+
struct k_heap *mod_heap = res->heap;
134135
struct module_resource *container;
135136

136137
if (list_is_empty(&res->free_cont_list)) {
137-
struct container_chunk *chunk = rzalloc(SOF_MEM_FLAG_USER, sizeof(*chunk));
138+
struct container_chunk *chunk = sof_heap_alloc(mod_heap, 0, sizeof(*chunk), 0);
138139
int i;
139140

140141
if (!chunk) {
141142
comp_err(mod->dev, "allocating more containers failed");
142143
return NULL;
143144
}
144145

146+
memset(chunk, 0, sizeof(*chunk));
147+
145148
list_item_append(&chunk->chunk_list, &res->cont_chunk_list);
146149
for (i = 0; i < ARRAY_SIZE(chunk->containers); i++)
147150
list_item_append(&chunk->containers[i].list, &res->free_cont_list);
@@ -239,8 +242,7 @@ void *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignme
239242
}
240243

241244
/* Allocate memory for module */
242-
ptr = rmalloc_align(SOF_MEM_FLAG_USER, size, alignment);
243-
245+
ptr = sof_heap_alloc(res->heap, 0, size, alignment);
244246
if (!ptr) {
245247
comp_err(mod->dev, "Failed to alloc %zu bytes %zu alignment for comp %#x.",
246248
size, alignment, dev_comp_id(mod->dev));
@@ -269,8 +271,7 @@ EXPORT_SYMBOL(mod_alloc_align);
269271
* Like comp_data_blob_handler_new() but the handler is automatically freed.
270272
*/
271273
#if CONFIG_COMP_BLOB
272-
struct comp_data_blob_handler *
273-
mod_data_blob_handler_new(struct processing_module *mod)
274+
struct comp_data_blob_handler *mod_data_blob_handler_new(struct processing_module *mod)
274275
{
275276
struct module_resources *res = &mod->priv.resources;
276277
struct comp_data_blob_handler *bhp;
@@ -340,7 +341,7 @@ static int free_contents(struct processing_module *mod, struct module_resource *
340341

341342
switch (container->type) {
342343
case MOD_RES_HEAP:
343-
rfree(container->ptr);
344+
sof_heap_free(res->heap, container->ptr);
344345
res->heap_usage -= container->size;
345346
return 0;
346347
#if CONFIG_COMP_BLOB
@@ -581,6 +582,7 @@ int module_reset(struct processing_module *mod)
581582
void mod_free_all(struct processing_module *mod)
582583
{
583584
struct module_resources *res = &mod->priv.resources;
585+
struct k_heap *mod_heap = res->heap;
584586
struct list_item *list;
585587
struct list_item *_list;
586588

@@ -599,7 +601,7 @@ void mod_free_all(struct processing_module *mod)
599601
container_of(list, struct container_chunk, chunk_list);
600602

601603
list_item_del(&chunk->chunk_list);
602-
rfree(chunk);
604+
sof_heap_free(mod_heap, chunk);
603605
}
604606
}
605607
EXPORT_SYMBOL(mod_free_all);

0 commit comments

Comments
 (0)