From 9754934c1cb57199d77bed31b354f72ba49ca029 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 25 Aug 2025 22:47:55 +0300 Subject: [PATCH 1/5] Audio: TDFB: 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/tdfb/tdfb.c | 32 +++++++++++--------------------- src/audio/tdfb/tdfb_comp.h | 3 +-- src/audio/tdfb/tdfb_direction.c | 30 +++++++----------------------- src/audio/tdfb/tdfb_ipc3.c | 2 +- 4 files changed, 20 insertions(+), 47 deletions(-) diff --git a/src/audio/tdfb/tdfb.c b/src/audio/tdfb/tdfb.c index 9fc04820ff75..9d76589c492d 100644 --- a/src/audio/tdfb/tdfb.c +++ b/src/audio/tdfb/tdfb.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -261,15 +260,16 @@ static inline int set_pass_func(struct processing_module *mod, enum sof_ipc_fram * Control code functions next. The processing is in fir_ C modules. */ -static void tdfb_free_delaylines(struct tdfb_comp_data *cd) +static void tdfb_free_delaylines(struct processing_module *mod) { + struct tdfb_comp_data *cd = module_get_private_data(mod); struct fir_state_32x16 *fir = cd->fir; int i = 0; /* Free the common buffer for all EQs and point then * each FIR channel delay line to NULL. */ - rfree(cd->fir_delay); + mod_free(mod, cd->fir_delay); cd->fir_delay = NULL; cd->fir_delay_size = 0; for (i = 0; i < PLATFORM_MAX_CHANNELS; i++) @@ -511,10 +511,10 @@ static int tdfb_setup(struct processing_module *mod, int source_nch, int sink_nc if (delay_size > cd->fir_delay_size) { /* Free existing FIR channels data if it was allocated */ - tdfb_free_delaylines(cd); + tdfb_free_delaylines(mod); /* Allocate all FIR channels data in a big chunk and clear it */ - cd->fir_delay = rballoc(SOF_MEM_FLAG_USER, delay_size); + cd->fir_delay = mod_alloc(mod, delay_size); if (!cd->fir_delay) { comp_err(mod->dev, "tdfb_setup(), delay allocation failed for size %d", delay_size); @@ -554,7 +554,7 @@ static int tdfb_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; @@ -571,10 +571,10 @@ static int tdfb_init(struct processing_module *mod) /* Initialize IPC for direction of arrival estimate update */ ret = tdfb_ipc_notification_init(mod); if (ret) - goto err_free_cd; + return ret; /* Handler for configuration 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; @@ -598,14 +598,8 @@ static int tdfb_init(struct processing_module *mod) return 0; err: - /* These are null if not used for IPC version */ - rfree(cd->ctrl_data); ipc_msg_free(cd->msg); - -err_free_cd: - rfree(cd); return ret; - } static int tdfb_free(struct processing_module *mod) @@ -615,11 +609,7 @@ static int tdfb_free(struct processing_module *mod) comp_dbg(mod->dev, "tdfb_free()"); ipc_msg_free(cd->msg); - tdfb_free_delaylines(cd); - comp_data_blob_handler_free(cd->model_handler); - tdfb_direction_free(cd); - rfree(cd->ctrl_data); - rfree(cd); + return 0; } @@ -780,7 +770,7 @@ static int tdfb_prepare(struct processing_module *mod, comp_dbg(dev, "dev_frames = %d, max_frames = %d", dev->frames, cd->max_frames); /* Initialize tracking */ - ret = tdfb_direction_init(cd, rate, source_channels); + ret = tdfb_direction_init(mod, rate, source_channels); if (!ret) { comp_info(dev, "max_lag = %d, xcorr_size = %zu", cd->direction.max_lag, cd->direction.d_size); @@ -803,7 +793,7 @@ static int tdfb_reset(struct processing_module *mod) comp_dbg(mod->dev, "tdfb_reset()"); - tdfb_free_delaylines(cd); + tdfb_free_delaylines(mod); cd->tdfb_func = NULL; for (i = 0; i < PLATFORM_MAX_CHANNELS; i++) diff --git a/src/audio/tdfb/tdfb_comp.h b/src/audio/tdfb/tdfb_comp.h index e2d5075e06b5..8c5689da1e65 100644 --- a/src/audio/tdfb/tdfb_comp.h +++ b/src/audio/tdfb/tdfb_comp.h @@ -118,10 +118,9 @@ void tdfb_fir_s32(struct tdfb_comp_data *cd, struct output_stream_buffer *bsink, int frames); #endif -int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int channels); +int tdfb_direction_init(struct processing_module *mod, int32_t fs, int channels); void tdfb_direction_copy_emphasis(struct tdfb_comp_data *cd, int channels, int *channel, int32_t x); void tdfb_direction_estimate(struct tdfb_comp_data *cd, int frames, int channels); -void tdfb_direction_free(struct tdfb_comp_data *cd); static inline void tdfb_cinc_s16(int16_t **ptr, int16_t *end, size_t size) { diff --git a/src/audio/tdfb/tdfb_direction.c b/src/audio/tdfb/tdfb_direction.c index 640fe4eaa06e..1f2f1e27944a 100644 --- a/src/audio/tdfb/tdfb_direction.c +++ b/src/audio/tdfb/tdfb_direction.c @@ -8,7 +8,6 @@ #include "tdfb_comp.h" #include -#include #include #include #include @@ -176,8 +175,9 @@ static bool line_array_mode_check(struct tdfb_comp_data *cd) return true; } -int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count) +int tdfb_direction_init(struct processing_module *mod, int32_t fs, int ch_count) { + struct tdfb_comp_data *cd = module_get_private_data(mod); struct sof_eq_iir_header *filt; int32_t *delay; int32_t d_max; @@ -200,7 +200,7 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count) /* Allocate delay lines for IIR filters and initialize them */ size = ch_count * iir_delay_size_df1(filt); - delay = rzalloc(SOF_MEM_FLAG_USER, size); + delay = mod_zalloc(mod, size); if (!delay) return -ENOMEM; @@ -225,9 +225,9 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count) cd->direction.max_lag = Q_MULTSR_32X32((int64_t)fs, t_max, 0, 15, 0) + 1; n = (cd->max_frames + (2 * cd->direction.max_lag + 1)) * ch_count; cd->direction.d_size = n * sizeof(int16_t); - cd->direction.d = rzalloc(SOF_MEM_FLAG_USER, cd->direction.d_size); + cd->direction.d = mod_zalloc(mod, cd->direction.d_size); if (!cd->direction.d) - goto err_free_iir; + return -ENOMEM; /* Set needed pointers to xcorr delay line, advance write pointer by max_lag to keep read * always behind write @@ -238,9 +238,9 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count) /* xcorr result is temporary but too large for stack so it is allocated here */ cd->direction.r_size = (2 * cd->direction.max_lag + 1) * sizeof(int32_t); - cd->direction.r = rzalloc(SOF_MEM_FLAG_USER, cd->direction.r_size); + cd->direction.r = mod_zalloc(mod, cd->direction.r_size); if (!cd->direction.r) - goto err_free_all; + return -ENOMEM; /* Check for line array mode */ cd->direction.line_array = line_array_mode_check(cd); @@ -249,22 +249,6 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count) cd->direction.az = 0; cd->direction.step_sign = 1; return 0; - -err_free_all: - rfree(cd->direction.d); - cd->direction.d = NULL; - -err_free_iir: - rfree(cd->direction.df1_delay); - cd->direction.df1_delay = NULL; - return -ENOMEM; -} - -void tdfb_direction_free(struct tdfb_comp_data *cd) -{ - rfree(cd->direction.df1_delay); - rfree(cd->direction.d); - rfree(cd->direction.r); } /* Measure level of one channel */ diff --git a/src/audio/tdfb/tdfb_ipc3.c b/src/audio/tdfb/tdfb_ipc3.c index 52662a141e56..d39002bec44c 100644 --- a/src/audio/tdfb/tdfb_ipc3.c +++ b/src/audio/tdfb/tdfb_ipc3.c @@ -30,7 +30,7 @@ static int init_get_ctl_ipc(struct processing_module *mod) struct tdfb_comp_data *cd = module_get_private_data(mod); int comp_id = dev_comp_id(mod->dev); - cd->ctrl_data = rzalloc(SOF_MEM_FLAG_USER, TDFB_GET_CTRL_DATA_SIZE); + cd->ctrl_data = mod_zalloc(mod, TDFB_GET_CTRL_DATA_SIZE); if (!cd->ctrl_data) return -ENOMEM; From 612002971c90248914416c2b2f45c787d7bd9974 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 25 Aug 2025 23:08:12 +0300 Subject: [PATCH 2/5] Audio: Template_comp: 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/template_comp/template.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/audio/template_comp/template.c b/src/audio/template_comp/template.c index fcd3fa294d03..67e8ad2f53d7 100644 --- a/src/audio/template_comp/template.c +++ b/src/audio/template_comp/template.c @@ -40,7 +40,7 @@ __cold static int template_comp_init(struct processing_module *mod) comp_info(dev, "template_comp_init()"); - cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); + cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -168,12 +168,9 @@ static int template_comp_reset(struct processing_module *mod) */ __cold static int template_comp_free(struct processing_module *mod) { - struct template_comp_comp_data *cd = module_get_private_data(mod); - assert_can_be_cold(); comp_dbg(mod->dev, "template_comp_free()"); - rfree(cd); return 0; } From 553acea64671ab5380bb4dab7615b14868ff5c6c Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 25 Aug 2025 23:18:59 +0300 Subject: [PATCH 3/5] modules: tensorflow: 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/tensorflow/tflm-classify.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/audio/tensorflow/tflm-classify.c b/src/audio/tensorflow/tflm-classify.c index 29b4b6a1af74..b8474e3c4e92 100644 --- a/src/audio/tensorflow/tflm-classify.c +++ b/src/audio/tensorflow/tflm-classify.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -61,25 +60,24 @@ __cold static int tflm_init(struct processing_module *mod) comp_info(dev, "tflm_init()"); - cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); + cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; md->private = cd; /* Handler for configuration 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; } /* Get configuration data and reset DRC state */ ret = comp_init_data_blob(cd->model_handler, bs, cfg->data); if (ret < 0) { comp_err(dev, "comp_init_data_blob() failed."); - goto cd_fail; + return ret; } /* hard coded atm */ @@ -100,20 +98,12 @@ __cold static int tflm_init(struct processing_module *mod) } return ret; - -cd_fail: - rfree(cd); - return ret; } __cold static int tflm_free(struct processing_module *mod) { - struct tflm_comp_data *cd = module_get_private_data(mod); - assert_can_be_cold(); - comp_data_blob_handler_free(cd->model_handler); - rfree(cd); return 0; } From 0d252c0149025538bcced14c6d8d5506ff22ff6d Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 25 Aug 2025 23:27:37 +0300 Subject: [PATCH 4/5] Audio: up_down_mixer: 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/up_down_mixer/up_down_mixer.c | 28 +++++++------------------ 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/audio/up_down_mixer/up_down_mixer.c b/src/audio/up_down_mixer/up_down_mixer.c index 3cc8308ad62d..9dff24b10ffc 100644 --- a/src/audio/up_down_mixer/up_down_mixer.c +++ b/src/audio/up_down_mixer/up_down_mixer.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -324,12 +323,6 @@ static int init_mix(struct processing_module *mod, static int up_down_mixer_free(struct processing_module *mod) { - struct up_down_mixer_data *cd = module_get_private_data(mod); - - rfree(cd->buf_in); - rfree(cd->buf_out); - rfree(cd); - return 0; } @@ -342,7 +335,7 @@ static int up_down_mixer_init(struct processing_module *mod) struct up_down_mixer_data *cd; int ret; - cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); + cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) { comp_free(dev); return -ENOMEM; @@ -350,12 +343,10 @@ static int up_down_mixer_init(struct processing_module *mod) mod_data->private = cd; - cd->buf_in = rballoc(SOF_MEM_FLAG_USER, mod->priv.cfg.base_cfg.ibs); - cd->buf_out = rballoc(SOF_MEM_FLAG_USER, mod->priv.cfg.base_cfg.obs); - if (!cd->buf_in || !cd->buf_out) { - ret = -ENOMEM; - goto err; - } + cd->buf_in = mod_alloc(mod, mod->priv.cfg.base_cfg.ibs); + cd->buf_out = mod_alloc(mod, mod->priv.cfg.base_cfg.obs); + if (!cd->buf_in || !cd->buf_out) + return -ENOMEM; switch (up_down_mixer->coefficients_select) { case DEFAULT_COEFFICIENTS: @@ -380,20 +371,15 @@ static int up_down_mixer_init(struct processing_module *mod) break; default: comp_err(dev, "unsupported coefficient type"); - ret = -EINVAL; - break; + return -EINVAL; } if (ret < 0) { comp_err(dev, "failed to initialize up_down_mix"); - goto err; + return ret; } return 0; - -err: - up_down_mixer_free(mod); - return ret; } static int From 839730494e2934005f03ee1081d928926ac47857 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 25 Aug 2025 23:37:18 +0300 Subject: [PATCH 5/5] audio: volume: 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/volume/volume.c | 5 ----- src/audio/volume/volume_ipc3.c | 8 ++------ src/audio/volume/volume_ipc4.c | 11 +++-------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/audio/volume/volume.c b/src/audio/volume/volume.c index 9f8aff265226..e0cf5ffe1271 100644 --- a/src/audio/volume/volume.c +++ b/src/audio/volume/volume.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -775,11 +774,7 @@ static int volume_free(struct processing_module *mod) struct vol_data *cd = module_get_private_data(mod); comp_dbg(mod->dev, "volume_free()"); - volume_peak_free(cd); - rfree(cd->vol); - rfree(cd); - return 0; } diff --git a/src/audio/volume/volume_ipc3.c b/src/audio/volume/volume_ipc3.c index e83ebf25cff1..9e8d018f1d8e 100644 --- a/src/audio/volume/volume_ipc3.c +++ b/src/audio/volume/volume_ipc3.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -81,7 +80,7 @@ int volume_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct vol_data)); + cd = mod_zalloc(mod, sizeof(struct vol_data)); if (!cd) return -ENOMEM; @@ -89,9 +88,8 @@ int volume_init(struct processing_module *mod) * malloc memory to store current volume 4 times to ensure the address * is 8-byte aligned for multi-way xtensa intrinsic operations. */ - cd->vol = rmalloc(SOF_MEM_FLAG_USER, vol_size); + cd->vol = mod_alloc(mod, vol_size); if (!cd->vol) { - rfree(cd); comp_err(dev, "Failed to allocate %zu", vol_size); return -ENOMEM; } @@ -158,8 +156,6 @@ int volume_init(struct processing_module *mod) break; default: comp_err(dev, "invalid ramp type %d", vol->ramp); - rfree(cd); - rfree(cd->vol); return -EINVAL; } diff --git a/src/audio/volume/volume_ipc4.c b/src/audio/volume/volume_ipc4.c index 889008657e8e..fc70358df90e 100644 --- a/src/audio/volume/volume_ipc4.c +++ b/src/audio/volume/volume_ipc4.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -128,7 +127,7 @@ int volume_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct vol_data)); + cd = mod_zalloc(mod, sizeof(struct vol_data)); if (!cd) return -ENOMEM; @@ -136,9 +135,8 @@ int volume_init(struct processing_module *mod) * malloc memory to store current volume 4 times to ensure the address * is 8-byte aligned for multi-way xtensa intrinsic operations. */ - cd->vol = rmalloc(SOF_MEM_FLAG_USER, vol_size); + cd->vol = mod_alloc(mod, vol_size); if (!cd->vol) { - rfree(cd); comp_err(dev, "Failed to allocate %d", vol_size); return -ENOMEM; } @@ -146,10 +144,8 @@ int volume_init(struct processing_module *mod) /* malloc memory to store temp peak volume 4 times to ensure the address * is 8-byte aligned for multi-way xtensa intrinsic operations. */ - cd->peak_vol = rzalloc(SOF_MEM_FLAG_USER, vol_size); + cd->peak_vol = mod_zalloc(mod, vol_size); if (!cd->peak_vol) { - rfree(cd->vol); - rfree(cd); comp_err(dev, "Failed to allocate %d for peak_vol", vol_size); return -ENOMEM; } @@ -196,7 +192,6 @@ void volume_peak_free(struct vol_data *cd) /* clear mailbox */ memset_s(®s, sizeof(regs), 0, sizeof(regs)); mailbox_sw_regs_write(cd->mailbox_offset, ®s, sizeof(regs)); - rfree(cd->peak_vol); } static int volume_set_volume(struct processing_module *mod, const uint8_t *data, int data_size)