Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/audio/tdfb/tdfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <ipc/control.h>
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <rtos/alloc.h>
#include <rtos/init.h>
#include <rtos/panic.h>
#include <rtos/string.h>
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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_balloc(mod, delay_size);
Copy link
Contributor Author

@jsarha jsarha Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will crash without this fix: #10324

if (!cd->fir_delay) {
comp_err(mod->dev, "tdfb_setup(), delay allocation failed for size %d",
delay_size);
Expand Down Expand Up @@ -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;

Expand All @@ -574,9 +574,9 @@ static int tdfb_init(struct processing_module *mod)
goto err_free_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.");
comp_err(dev, "mod_data_blob_handler_new() failed.");
ret = -ENOMEM;
goto err;
}
Expand All @@ -599,11 +599,12 @@ static int tdfb_init(struct processing_module *mod)

err:
/* These are null if not used for IPC version */
rfree(cd->ctrl_data);
mod_free(mod, cd->ctrl_data);
ipc_msg_free(cd->msg);
mod_data_blob_handler_free(mod, cd->model_handler);

err_free_cd:
rfree(cd);
mod_free(mod, cd);
return ret;

}
Expand All @@ -615,11 +616,11 @@ 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);
tdfb_free_delaylines(mod);
mod_data_blob_handler_free(mod, cd->model_handler);
tdfb_direction_free(mod);
mod_free(mod, cd->ctrl_data);
mod_free(mod, cd);
return 0;
}

Expand Down Expand Up @@ -780,7 +781,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);
Expand All @@ -803,7 +804,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++)
Expand Down
4 changes: 2 additions & 2 deletions src/audio/tdfb/tdfb_comp.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ 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);
void tdfb_direction_free(struct processing_module *mod);

static inline void tdfb_cinc_s16(int16_t **ptr, int16_t *end, size_t size)
{
Expand Down
24 changes: 13 additions & 11 deletions src/audio/tdfb/tdfb_direction.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "tdfb_comp.h"

#include <ipc/topology.h>
#include <rtos/alloc.h>
#include <sof/math/iir_df1.h>
#include <sof/math/trig.h>
#include <sof/math/sqrt.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -225,7 +225,7 @@ 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;

Expand All @@ -238,7 +238,7 @@ 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;

Expand All @@ -251,20 +251,22 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count)
return 0;

err_free_all:
rfree(cd->direction.d);
mod_free(mod, cd->direction.d);
cd->direction.d = NULL;

err_free_iir:
rfree(cd->direction.df1_delay);
mod_free(mod, cd->direction.df1_delay);
cd->direction.df1_delay = NULL;
return -ENOMEM;
}

void tdfb_direction_free(struct tdfb_comp_data *cd)
void tdfb_direction_free(struct processing_module *mod)
{
rfree(cd->direction.df1_delay);
rfree(cd->direction.d);
rfree(cd->direction.r);
struct tdfb_comp_data *cd = module_get_private_data(mod);

mod_free(mod, cd->direction.df1_delay);
mod_free(mod, cd->direction.d);
mod_free(mod, cd->direction.r);
}

/* Measure level of one channel */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/tdfb/tdfb_ipc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/audio/template/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ __cold static int template_init(struct processing_module *mod)

comp_info(dev, "template_init()");

cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
cd = mod_zalloc(mod, sizeof(*cd));
if (!cd)
return -ENOMEM;

Expand Down Expand Up @@ -173,7 +173,7 @@ __cold static int template_free(struct processing_module *mod)
assert_can_be_cold();

comp_dbg(mod->dev, "template_free()");
rfree(cd);
mod_free(mod, cd);
return 0;
}

Expand Down
25 changes: 13 additions & 12 deletions src/audio/tensorflow/tflm-classify.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <module/module/llext.h>
#include <rtos/alloc.h>
#include <rtos/init.h>
#include <rtos/panic.h>
#include <rtos/string.h>
Expand Down Expand Up @@ -61,25 +60,25 @@ __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.");
comp_err(dev, "mod_data_blob_handler_new() failed.");
ret = -ENOMEM;
goto cd_fail;
goto fail;
}

/* 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;
goto fail;
}

/* hard coded atm */
Expand All @@ -89,20 +88,22 @@ __cold static int tflm_init(struct processing_module *mod)
ret = TF_SetModel(&cd->tfc, NULL);
if (!ret) {
comp_err(dev, "failed to set model");
return ret;
goto fail;
}

/* initialise ops */
ret = TF_InitOps(&cd->tfc);
if (!ret) {
comp_err(dev, "failed to init ops");
return ret;
goto fail;
}

return ret;

cd_fail:
rfree(cd);
fail:
/* Passing NULL pointer to free functions is Ok */
mod_data_blob_handler_free(mod, cd->model_handler);
mod_free(mod, cd);
return ret;
}

Expand All @@ -112,8 +113,8 @@ __cold static int tflm_free(struct processing_module *mod)

assert_can_be_cold();

comp_data_blob_handler_free(cd->model_handler);
rfree(cd);
mod_data_blob_handler_free(mod, cd->model_handler);
mod_free(mod, cd);
return 0;
}

Expand Down
13 changes: 6 additions & 7 deletions src/audio/up_down_mixer/up_down_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <sof/audio/pipeline.h>
#include <rtos/panic.h>
#include <sof/ipc/msg.h>
#include <rtos/alloc.h>
#include <rtos/cache.h>
#include <rtos/init.h>
#include <sof/lib/notifier.h>
Expand Down Expand Up @@ -326,9 +325,9 @@ 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);
mod_free(mod, cd->buf_in);
mod_free(mod, cd->buf_out);
mod_free(mod, cd);

return 0;
}
Expand All @@ -342,16 +341,16 @@ 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;
}

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);
cd->buf_in = mod_balloc(mod, mod->priv.cfg.base_cfg.ibs);
cd->buf_out = mod_balloc(mod, mod->priv.cfg.base_cfg.obs);
if (!cd->buf_in || !cd->buf_out) {
ret = -ENOMEM;
goto err;
Expand Down
Loading