From 33ee47e6e1a5fdacb44e06399a936d1e2f033e03 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Sun, 24 Aug 2025 21:27:33 +0300 Subject: [PATCH 1/5] Audio: mixin_mixout: Memory, blob, and fast_get allocs to module API Allocate all memory, blob handlers, and fast_get() buffers through module API mod_alloc() and friends and remove all redundant rfree(), comp_data_blob_handler_free(), and fast_put() calls from module unload functions and init error branches. Signed-off-by: Jyri Sarha --- src/audio/mixin_mixout/mixin_mixout.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/audio/mixin_mixout/mixin_mixout.c b/src/audio/mixin_mixout/mixin_mixout.c index 5043d02920f0..bcc2fe59314d 100644 --- a/src/audio/mixin_mixout/mixin_mixout.c +++ b/src/audio/mixin_mixout/mixin_mixout.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -139,7 +138,7 @@ static int mixin_init(struct processing_module *mod) comp_dbg(dev, "mixin_init()"); - md = rzalloc(SOF_MEM_FLAG_USER, sizeof(*md)); + md = mod_zalloc(mod, sizeof(*md)); if (!md) return -ENOMEM; @@ -166,7 +165,7 @@ static int mixout_init(struct processing_module *mod) comp_dbg(dev, "mixout_new()"); - mo_data = rzalloc(SOF_MEM_FLAG_USER, sizeof(*mo_data)); + mo_data = mod_zalloc(mod, sizeof(*mo_data)); if (!mo_data) return -ENOMEM; @@ -180,17 +179,11 @@ static int mixout_init(struct processing_module *mod) static int mixin_free(struct processing_module *mod) { - struct mixin_data *md = module_get_private_data(mod); - - rfree(md); - return 0; } static int mixout_free(struct processing_module *mod) { - rfree(module_get_private_data(mod)); - return 0; } From 43bba63653d5490a7070032324b7dd7302168dc6 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Sun, 24 Aug 2025 21:35:29 +0300 Subject: [PATCH 2/5] Audio: Mux: Memory, blob, and fast_get allocs to module API Allocate all memory, blob handlers, and fast_get() buffers through module API mod_alloc() and friends and remove all redundant rfree(), comp_data_blob_handler_free(), and fast_put() calls from module unload functions and init error branches. Signed-off-by: Jyri Sarha --- src/audio/mux/mux.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index bbcf1b544e90..99545f4629a1 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -94,36 +93,27 @@ static int mux_demux_common_init(struct processing_module *mod, enum sof_comp_ty return -EINVAL; } - cd = rzalloc(SOF_MEM_FLAG_USER, - sizeof(*cd) + MUX_BLOB_STREAMS_SIZE); + cd = mod_zalloc(mod, sizeof(*cd) + MUX_BLOB_STREAMS_SIZE); if (!cd) return -ENOMEM; - cd->model_handler = comp_data_blob_handler_new(dev); + cd->model_handler = mod_data_blob_handler_new(mod); if (!cd->model_handler) { comp_err(dev, "comp_data_blob_handler_new() failed."); - ret = -ENOMEM; - goto err; + return -ENOMEM; } module_data->private = cd; ret = comp_init_data_blob(cd->model_handler, cfg->size, cfg->init_data); if (ret < 0) { comp_err(dev, "comp_init_data_blob() failed."); - goto err_init; + return ret; } mod->verify_params_flags = BUFF_PARAMS_CHANNELS; mod->no_pause = true; cd->comp_type = type; return 0; - -err_init: - comp_data_blob_handler_free(cd->model_handler); - -err: - rfree(cd); - return ret; } static int mux_init(struct processing_module *mod) @@ -135,12 +125,8 @@ static int mux_init(struct processing_module *mod) static int mux_free(struct processing_module *mod) { - struct comp_data *cd = module_get_private_data(mod); - comp_dbg(mod->dev, "mux_free()"); - comp_data_blob_handler_free(cd->model_handler); - rfree(cd); return 0; } From 4aeb313c9eb66227bca791990607828a86763d18 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 25 Aug 2025 15:22:57 +0300 Subject: [PATCH 3/5] Audio: NXP: Memory, blob, and fast_get allocs to module API Allocate all memory, blob handlers, and fast_get() buffers through module API mod_alloc() and friends and remove all redundant rfree(), comp_data_blob_handler_free(), and fast_put() calls from module unload functions and init error branches. Signed-off-by: Jyri Sarha --- src/audio/nxp/eap.c | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/src/audio/nxp/eap.c b/src/audio/nxp/eap.c index 4e6e2c5eb535..bfa1982d1f44 100644 --- a/src/audio/nxp/eap.c +++ b/src/audio/nxp/eap.c @@ -5,7 +5,6 @@ // Author: Daniel Baluta #include -#include #include #include #include @@ -93,7 +92,7 @@ static int nxp_eap_init(struct processing_module *mod) tr_info(mod->dev, "NXP EAP library, platform: %s version:%s", info.pPlatform, info.pVersionNumber); - eap = rballoc(SOF_MEM_FLAG_USER, sizeof(*eap)); + eap = mod_alloc(mod, sizeof(*eap)); if (!eap) { comp_err(dev, "nxp_eap_init() failed to allocate module private data"); return -ENOMEM; @@ -106,7 +105,6 @@ static int nxp_eap_init(struct processing_module *mod) lvm_ret = LVM_GetMemoryTable(LVM_NULL, &eap->mem_tab, &eap->inst_params); if (lvm_ret != LVM_SUCCESS) { comp_err(dev, "nxp_eap_init() failed to get memory table %d", lvm_ret); - rfree(eap); return -EINVAL; } @@ -115,54 +113,31 @@ static int nxp_eap_init(struct processing_module *mod) eap->mem_tab.Region[i].pBaseAddress = NULL; for (int i = 0; i < LVM_NR_MEMORY_REGIONS; i++) { - eap->mem_tab.Region[i].pBaseAddress = rballoc(SOF_MEM_FLAG_USER, - eap->mem_tab.Region[i].Size); + eap->mem_tab.Region[i].pBaseAddress = mod_alloc(mod, eap->mem_tab.Region[i].Size); if (!eap->mem_tab.Region[i].pBaseAddress) { comp_err(dev, "nxp_eap_init() failed to allocate memory for region %d", i); - ret = -ENOMEM; - goto free_mem; + return -ENOMEM; } } lvm_ret = LVM_GetInstanceHandle(&eap->instance, &eap->mem_tab, &eap->inst_params); if (lvm_ret != LVM_SUCCESS) { comp_err(dev, "nxp_eap_init() failed to get instance handle err: %d", lvm_ret); - ret = -EINVAL; - goto free_mem; + return -EINVAL; } /* default parameters, no effects */ memcpy(&eap->ctrl_params, &ControlParamSet_allEffectOff, sizeof(eap->ctrl_params)); return 0; - -free_mem: - for (int i = 0; i < LVM_NR_MEMORY_REGIONS; i++) { - if (eap->mem_tab.Region[i].pBaseAddress) { - rfree(eap->mem_tab.Region[i].pBaseAddress); - eap->mem_tab.Region[i].pBaseAddress = NULL; - } - } - rfree(eap); - return ret; } static int nxp_eap_free(struct processing_module *mod) { struct comp_dev *dev = mod->dev; - struct nxp_eap_data *eap = module_get_private_data(mod); comp_dbg(dev, "nxp_eap_free()"); - for (int i = 0; i < LVM_NR_MEMORY_REGIONS; i++) { - if (eap->mem_tab.Region[i].pBaseAddress) { - rfree(eap->mem_tab.Region[i].pBaseAddress); - eap->mem_tab.Region[i].pBaseAddress = NULL; - } - } - - rfree(eap); - return 0; } @@ -189,15 +164,13 @@ static int nxp_eap_prepare(struct processing_module *mod, */ eap->buffer_bytes = NXP_EAP_DEFAULT_MAX_BLOCK_SIZE; - md->mpd.in_buff = rballoc_align(SOF_MEM_FLAG_USER, eap->buffer_bytes, 32); + md->mpd.in_buff = mod_alloc_align(mod, eap->buffer_bytes, 32); if (!md->mpd.in_buff) return -ENOMEM; - md->mpd.out_buff = rballoc_align(SOF_MEM_FLAG_USER, eap->buffer_bytes, 32); - if (!md->mpd.out_buff) { - rfree(md->mpd.in_buff); + md->mpd.out_buff = mod_alloc_align(mod, eap->buffer_bytes, 32); + if (!md->mpd.out_buff) return -ENOMEM; - } md->mpd.in_buff_size = eap->buffer_bytes; md->mpd.out_buff_size = eap->buffer_bytes; @@ -213,13 +186,13 @@ static int nxp_eap_reset(struct processing_module *mod) comp_dbg(dev, "nxp_eap_reset"); if (md->mpd.in_buff) { - rfree(md->mpd.in_buff); + mod_free(mod, md->mpd.in_buff); md->mpd.in_buff = NULL; md->mpd.in_buff_size = 0; } if (md->mpd.out_buff) { - rfree(md->mpd.out_buff); + mod_free(mod, md->mpd.out_buff); md->mpd.out_buff = NULL; md->mpd.out_buff_size = 0; } From f69470de31ebe329f54adb7fb62e4cc70bbe1f3e Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 25 Aug 2025 21:58:00 +0300 Subject: [PATCH 4/5] Audio: RTNR: Memory, blob, and fast_get allocs to module API Allocate all memory, blob handlers, and fast_get() buffers through module API mod_alloc() and friends and remove all redundant rfree(), comp_data_blob_handler_free(), and fast_put() calls from module unload functions and init error branches. However, the rtnr_stub's heap access, rtk_alloc() and rtk_free() still use heap directly like before. Signed-off-by: Jyri Sarha --- src/audio/rtnr/rtnr.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/audio/rtnr/rtnr.c b/src/audio/rtnr/rtnr.c index 541f985753a1..7dd99302dbed 100644 --- a/src/audio/rtnr/rtnr.c +++ b/src/audio/rtnr/rtnr.c @@ -241,7 +241,7 @@ static int rtnr_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); + cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -250,17 +250,16 @@ static int rtnr_init(struct processing_module *mod) cd->process_enable = true; /* Handler for component data */ - cd->model_handler = comp_data_blob_handler_new(dev); + cd->model_handler = mod_data_blob_handler_new(mod); if (!cd->model_handler) { comp_err(dev, "comp_data_blob_handler_new() failed."); - ret = -ENOMEM; - goto cd_fail; + return -ENOMEM; } ret = comp_init_data_blob(cd->model_handler, bs, ipc_rtnr->data); if (ret < 0) { comp_err(dev, "comp_init_data_blob() failed with error: %d", ret); - goto cd_fail; + return ret; } /* Component defaults */ @@ -269,8 +268,7 @@ static int rtnr_init(struct processing_module *mod) cd->rtk_agl = RTKMA_API_Context_Create(cd->process_sample_rate); if (cd->rtk_agl == 0) { comp_err(dev, "RTKMA_API_Context_Create failed."); - ret = -EINVAL; - goto cd_fail; + return -EINVAL; } comp_info(dev, "RTKMA_API_Context_Create succeeded."); @@ -283,11 +281,6 @@ static int rtnr_init(struct processing_module *mod) /* Done. */ return 0; - -cd_fail: - comp_data_blob_handler_free(cd->model_handler); - rfree(cd); - return ret; } static int rtnr_free(struct processing_module *mod) @@ -296,11 +289,8 @@ static int rtnr_free(struct processing_module *mod) comp_info(mod->dev, "rtnr_free()"); - comp_data_blob_handler_free(cd->model_handler); - RTKMA_API_Context_Free(cd->rtk_agl); - rfree(cd); return 0; } From fce00cd9bd432fe32c02e3da9118c4b327adf738 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 25 Aug 2025 22:09:36 +0300 Subject: [PATCH 5/5] Audio: Selector: Memory, blob, and fast_get allocs to module API Allocate all memory, blob handlers, and fast_get() buffers through module API mod_alloc() and friends and remove all redundant rfree(), comp_data_blob_handler_free(), and fast_put() calls from module unload functions and init error branches. The IPC3 implementation of selector uses the component interface directly and can not use the new module API. Signed-off-by: Jyri Sarha --- src/audio/selector/selector.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/audio/selector/selector.c b/src/audio/selector/selector.c index 201ed9fa6567..e7663ad8286b 100644 --- a/src/audio/selector/selector.c +++ b/src/audio/selector/selector.c @@ -613,7 +613,7 @@ static int selector_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); + cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -729,12 +729,8 @@ static int selector_verify_params(struct processing_module *mod, */ static int selector_free(struct processing_module *mod) { - struct comp_data *cd = module_get_private_data(mod); - comp_dbg(mod->dev, "selector_free()"); - rfree(cd); - return 0; }