diff --git a/src/audio/crossover/crossover.c b/src/audio/crossover/crossover.c index a8c31eecdb55..5c1dca7cc9aa 100644 --- a/src/audio/crossover/crossover.c +++ b/src/audio/crossover/crossover.c @@ -296,19 +296,10 @@ static int crossover_init(struct processing_module *mod) struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; struct comp_data *cd; - const struct module_config *ipc_crossover = &md->cfg; - size_t bs = ipc_crossover->size; int ret; comp_info(dev, "entry"); - /* Check that the coefficients blob size is sane */ - if (bs > SOF_CROSSOVER_MAX_SIZE) { - comp_err(dev, "blob size (%d) exceeds maximum allowed size (%i)", - bs, SOF_CROSSOVER_MAX_SIZE); - return -ENOMEM; - } - cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -323,13 +314,6 @@ static int crossover_init(struct processing_module *mod) goto cd_fail; } - /* Get configuration data and reset Crossover state */ - ret = comp_init_data_blob(cd->model_handler, bs, ipc_crossover->data); - if (ret < 0) { - comp_err(dev, "comp_init_data_blob() failed."); - goto cd_fail; - } - ret = crossover_output_pin_init(mod); if (ret < 0) { comp_err(dev, "failed."); @@ -527,6 +511,7 @@ static int crossover_prepare(struct processing_module *mod, struct comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; struct comp_buffer *source, *sink; + size_t data_size; int channels; comp_info(dev, "entry"); @@ -558,13 +543,14 @@ static int crossover_prepare(struct processing_module *mod, comp_info(dev, "source_format=%d, sink_formats=%d, nch=%d", cd->source_format, cd->source_format, channels); - cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); + cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); /* Initialize Crossover */ - if (cd->config && crossover_validate_config(mod, cd->config) < 0) { - /* If config is invalid then delete it */ + if (cd->config && + (!data_size || crossover_validate_config(mod, cd->config) < 0)) { + /* If the configuration is invalid fail the prepare */ comp_err(dev, "invalid binary config format"); - crossover_free_config(&cd->config); + return -EINVAL; } if (cd->config) { diff --git a/src/audio/dcblock/dcblock.c b/src/audio/dcblock/dcblock.c index ea4159dcd432..5f0935a2bc29 100644 --- a/src/audio/dcblock/dcblock.c +++ b/src/audio/dcblock/dcblock.c @@ -80,10 +80,7 @@ static int dcblock_init(struct processing_module *mod) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; - struct module_config *ipc_dcblock = &md->cfg; struct comp_data *cd; - size_t bs = ipc_dcblock->size; - int ret; comp_info(dev, "entry"); @@ -98,24 +95,11 @@ static int dcblock_init(struct processing_module *mod) cd->model_handler = comp_data_blob_handler_new(dev); if (!cd->model_handler) { comp_err(dev, "comp_data_blob_handler_new() failed."); - ret = -ENOMEM; - goto err_cd; - } - - ret = comp_init_data_blob(cd->model_handler, bs, ipc_dcblock->data); - if (ret < 0) { - comp_err(dev, "comp_init_data_blob() failed with error: %d", ret); - goto err_model_cd; + rfree(cd); + return -ENOMEM; } return 0; - -err_model_cd: - comp_data_blob_handler_free(cd->model_handler); - -err_cd: - rfree(cd); - return ret; } /** @@ -190,6 +174,7 @@ static int dcblock_prepare(struct processing_module *mod, struct comp_data *cd = module_get_private_data(mod); struct comp_buffer *sourceb, *sinkb; struct comp_dev *dev = mod->dev; + size_t data_size; comp_info(dev, "entry"); @@ -219,8 +204,8 @@ static int dcblock_prepare(struct processing_module *mod, comp_info(mod->dev, "source_format=%d, sink_format=%d", cd->source_format, cd->sink_format); - cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); - if (cd->config) + cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); + if (cd->config && data_size > 0) dcblock_copy_coefficients(mod); else dcblock_set_passthrough(mod); diff --git a/src/audio/drc/drc.c b/src/audio/drc/drc.c index 3627b03b3a47..71d93496b766 100644 --- a/src/audio/drc/drc.c +++ b/src/audio/drc/drc.c @@ -147,24 +147,13 @@ __cold static int drc_init(struct processing_module *mod) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; - struct module_config *cfg = &md->cfg; struct drc_comp_data *cd; - size_t bs = cfg->size; int ret; assert_can_be_cold(); comp_info(dev, "entry"); - /* Check first before proceeding with dev and cd that coefficients - * blob size is sane. - */ - if (bs > SOF_DRC_MAX_SIZE) { - comp_err(dev, "error: configuration blob size = %u > %d", - bs, SOF_DRC_MAX_SIZE); - return -EINVAL; - } - cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -179,13 +168,6 @@ __cold static int drc_init(struct processing_module *mod) goto cd_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; - } - drc_reset_state(mod, &cd->state); /* Initialize DRC to enabled. If defined by topology, a control may set @@ -344,6 +326,7 @@ static int drc_prepare(struct processing_module *mod, struct drc_comp_data *cd = module_get_private_data(mod); struct comp_buffer *sourceb, *sinkb; struct comp_dev *dev = mod->dev; + size_t data_size; int channels; int rate; int ret; @@ -369,8 +352,8 @@ static int drc_prepare(struct processing_module *mod, /* Initialize DRC */ comp_info(dev, "source_format=%d", cd->source_format); - cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); - if (cd->config) { + cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); + if (cd->config && data_size > 0) { ret = drc_setup(mod, channels, rate); if (ret < 0) { comp_err(dev, "error: drc_setup failed."); diff --git a/src/audio/eq_fir/eq_fir.c b/src/audio/eq_fir/eq_fir.c index 167debe03570..39cce7fd7974 100644 --- a/src/audio/eq_fir/eq_fir.c +++ b/src/audio/eq_fir/eq_fir.c @@ -247,23 +247,11 @@ static int eq_fir_init(struct processing_module *mod) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; - struct module_config *cfg = &md->cfg; struct comp_data *cd = NULL; - size_t bs = cfg->size; int i; - int ret; comp_info(dev, "entry"); - /* Check first before proceeding with dev and cd that coefficients - * blob size is sane. - */ - if (bs > SOF_EQ_FIR_MAX_SIZE) { - comp_err(dev, "coefficients blob size = %zu > SOF_EQ_FIR_MAX_SIZE", - bs); - return -EINVAL; - } - cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -277,31 +265,16 @@ static int eq_fir_init(struct processing_module *mod) cd->model_handler = mod_data_blob_handler_new(mod); if (!cd->model_handler) { comp_err(dev, "mod_data_blob_handler_new() failed."); - ret = -ENOMEM; - goto err; + mod_free(mod, cd); + return -ENOMEM; } md->private = cd; - /* Allocate and make a copy of the coefficients blob and reset FIR. If - * the EQ is configured later in run-time the size is zero. - */ - ret = comp_init_data_blob(cd->model_handler, bs, cfg->init_data); - if (ret < 0) { - comp_err(dev, "comp_init_data_blob() failed."); - goto err_init; - } - for (i = 0; i < PLATFORM_MAX_CHANNELS; i++) fir_reset(&cd->fir[i]); return 0; - -err_init: - mod_data_blob_handler_free(mod, cd->model_handler); -err: - mod_free(mod, cd); - return ret; } static int eq_fir_free(struct processing_module *mod) @@ -413,6 +386,7 @@ static int eq_fir_prepare(struct processing_module *mod, int channels; enum sof_ipc_frame frame_fmt; int ret = 0; + size_t data_size; comp_dbg(dev, "entry"); @@ -435,8 +409,8 @@ static int eq_fir_prepare(struct processing_module *mod, frame_fmt = audio_stream_get_frm_fmt(&sourceb->stream); cd->eq_fir_func = eq_fir_passthrough; - cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); - if (cd->config) { + cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); + if (cd->config && data_size > 0) { ret = eq_fir_setup(mod, channels); if (ret < 0) comp_err(dev, "eq_fir_setup failed."); diff --git a/src/audio/eq_iir/eq_iir.c b/src/audio/eq_iir/eq_iir.c index ecce61521bc1..0f07fbeda03c 100644 --- a/src/audio/eq_iir/eq_iir.c +++ b/src/audio/eq_iir/eq_iir.c @@ -44,19 +44,11 @@ static int eq_iir_init(struct processing_module *mod) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; - struct module_config *cfg = &md->cfg; struct comp_data *cd; - size_t bs = cfg->size; - int i, ret; + int i; comp_info(dev, "entry"); - /* Check first before proceeding with dev and cd that coefficients blob size is sane */ - if (bs > SOF_EQ_IIR_MAX_SIZE) { - comp_err(dev, "coefficients blob size %zu exceeds maximum", bs); - return -EINVAL; - } - cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -67,28 +59,14 @@ static int eq_iir_init(struct processing_module *mod) cd->model_handler = mod_data_blob_handler_new(mod); if (!cd->model_handler) { comp_err(dev, "mod_data_blob_handler_new() failed."); - ret = -ENOMEM; - goto err; - } - - /* Allocate and make a copy of the coefficients blob and reset IIR. If - * the EQ is configured later in run-time the size is zero. - */ - ret = comp_init_data_blob(cd->model_handler, bs, cfg->data); - if (ret < 0) { - comp_err(dev, "comp_init_data_blob() failed with error: %d", ret); - goto err; + mod_free(mod, cd); + return -ENOMEM; } for (i = 0; i < PLATFORM_MAX_CHANNELS; i++) iir_reset_df1(&cd->iir[i]); return 0; - -err: - mod_data_blob_handler_free(mod, cd->model_handler); - mod_free(mod, cd); - return ret; } static int eq_iir_free(struct processing_module *mod) @@ -180,6 +158,7 @@ static int eq_iir_prepare(struct processing_module *mod, struct comp_dev *dev = mod->dev; enum sof_ipc_frame source_format; enum sof_ipc_frame sink_format; + size_t data_size; int channels; int ret = 0; @@ -204,7 +183,7 @@ static int eq_iir_prepare(struct processing_module *mod, source_format = audio_stream_get_frm_fmt(&sourceb->stream); sink_format = audio_stream_get_frm_fmt(&sinkb->stream); - cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); + cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); /* Initialize EQ */ comp_info(dev, "source_format=%d, sink_format=%d", @@ -213,7 +192,7 @@ static int eq_iir_prepare(struct processing_module *mod, eq_iir_set_passthrough_func(cd, source_format, sink_format); /* Initialize EQ */ - if (cd->config) { + if (cd->config && data_size > 0) { ret = eq_iir_new_blob(mod, source_format, sink_format, channels); if (ret) return ret; diff --git a/src/audio/mfcc/mfcc.c b/src/audio/mfcc/mfcc.c index 9a5846edaffd..6a168903edbf 100644 --- a/src/audio/mfcc/mfcc.c +++ b/src/audio/mfcc/mfcc.c @@ -72,20 +72,10 @@ static int mfcc_init(struct processing_module *mod) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; - struct module_config *cfg = &md->cfg; struct mfcc_comp_data *cd = NULL; - size_t bs = cfg->size; - int ret; comp_info(dev, "entry"); - /* Check first that configuration blob size is sane */ - if (bs > SOF_MFCC_CONFIG_MAX_SIZE) { - comp_err(dev, "error: configuration blob size %zu exceeds %d", - bs, SOF_MFCC_CONFIG_MAX_SIZE); - return -EINVAL; - } - cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -95,25 +85,11 @@ static int mfcc_init(struct processing_module *mod) 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; - } - - /* Get configuration data */ - ret = comp_init_data_blob(cd->model_handler, bs, cfg->init_data); - if (ret < 0) { - comp_err(mod->dev, "comp_init_data_blob() failed."); - goto err_init; + mod_free(mod, cd); + return -ENOMEM; } return 0; - -err_init: - comp_data_blob_handler_free(cd->model_handler); - -err: - mod_free(mod, cd); - return ret; } static int mfcc_free(struct processing_module *mod) @@ -183,6 +159,7 @@ static int mfcc_prepare(struct processing_module *mod, struct comp_dev *dev = mod->dev; enum sof_ipc_frame source_format; enum sof_ipc_frame sink_format; + size_t data_size; uint32_t sink_period_bytes; int ret; @@ -211,10 +188,10 @@ static int mfcc_prepare(struct processing_module *mod, goto err; } - cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); + cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); /* Initialize MFCC, max_frames is set to dev->frames + 4 */ - if (cd->config) { + if (cd->config && data_size > 0) { ret = mfcc_setup(mod, dev->frames + 4, audio_stream_get_rate(&sourceb->stream), audio_stream_get_channels(&sourceb->stream)); if (ret < 0) { diff --git a/src/audio/multiband_drc/multiband_drc.c b/src/audio/multiband_drc/multiband_drc.c index 51835ba37264..84a079134ea1 100644 --- a/src/audio/multiband_drc/multiband_drc.c +++ b/src/audio/multiband_drc/multiband_drc.c @@ -226,22 +226,10 @@ static int multiband_drc_init(struct processing_module *mod) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; - struct module_config *cfg = &md->cfg; struct multiband_drc_comp_data *cd; - size_t bs = cfg->size; - int ret; comp_info(dev, "entry"); - /* Check first before proceeding with dev and cd that coefficients - * blob size is sane. - */ - if (bs > SOF_MULTIBAND_DRC_MAX_BLOB_SIZE) { - comp_err(dev, "error: configuration blob size = %u > %d", - bs, SOF_MULTIBAND_DRC_MAX_BLOB_SIZE); - return -EINVAL; - } - cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -260,24 +248,13 @@ static int multiband_drc_init(struct processing_module *mod) 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; + mod_free(mod, cd); + 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; - } multiband_drc_reset_state(mod, &cd->state); return 0; - -cd_fail: - mod_data_blob_handler_free(mod, cd->model_handler); - mod_free(mod, cd); - return ret; } __cold static int multiband_drc_free(struct processing_module *mod) @@ -365,6 +342,7 @@ static int multiband_drc_prepare(struct processing_module *mod, struct multiband_drc_comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; struct comp_buffer *sourceb; + size_t data_size; int channels; int rate; int ret = 0; @@ -390,8 +368,8 @@ static int multiband_drc_prepare(struct processing_module *mod, /* Initialize DRC */ comp_dbg(dev, "source_format=%d, sink_format=%d", cd->source_format, cd->source_format); - cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); - if (cd->config) { + cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); + if (cd->config && data_size > 0) { ret = multiband_drc_setup(mod, channels, rate); if (ret < 0) { comp_err(dev, "error: multiband_drc_setup failed."); diff --git a/src/audio/tdfb/tdfb.c b/src/audio/tdfb/tdfb.c index ad88025f7250..fa6a207d49e6 100644 --- a/src/audio/tdfb/tdfb.c +++ b/src/audio/tdfb/tdfb.c @@ -537,21 +537,12 @@ static int tdfb_init(struct processing_module *mod) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; - struct module_config *cfg = &md->cfg; struct tdfb_comp_data *cd; - size_t bs = cfg->size; int ret; int i; comp_info(dev, "entry"); - /* Check first that configuration blob size is sane */ - if (bs > SOF_TDFB_MAX_SIZE) { - comp_err(dev, "error: configuration blob size = %zu > %d", - bs, SOF_TDFB_MAX_SIZE); - return -EINVAL; - } - cd = mod_zalloc(mod, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -579,13 +570,6 @@ static int tdfb_init(struct processing_module *mod) goto err; } - /* Get configuration data and reset FIR filters */ - ret = comp_init_data_blob(cd->model_handler, bs, cfg->data); - if (ret < 0) { - comp_err(dev, "comp_init_data_blob() failed."); - goto err; - } - for (i = 0; i < PLATFORM_MAX_CHANNELS; i++) fir_reset(&cd->fir[i]); @@ -723,6 +707,7 @@ static int tdfb_prepare(struct processing_module *mod, struct comp_buffer *sourceb, *sinkb; struct comp_dev *dev = mod->dev; enum sof_ipc_frame frame_fmt; + size_t data_size; int source_channels; int sink_channels; int rate; @@ -752,8 +737,9 @@ static int tdfb_prepare(struct processing_module *mod, rate = audio_stream_get_rate(&sourceb->stream); /* Initialize filter */ - cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL); - if (!cd->config) { + cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); + if (!cd->config || !data_size) { + comp_err(dev, "Missing a configuration blob."); ret = -EINVAL; goto out; } diff --git a/test/cmocka/src/audio/eq_fir/eq_fir_process.c b/test/cmocka/src/audio/eq_fir/eq_fir_process.c index a7087fa7c470..5e3b1dd5b156 100644 --- a/test/cmocka/src/audio/eq_fir/eq_fir_process.c +++ b/test/cmocka/src/audio/eq_fir/eq_fir_process.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "../../util.h" #include "../../../include/cmocka_chirp_2ch.h" @@ -69,23 +70,48 @@ static int setup_group(void **state) static struct sof_ipc_comp_process *create_eq_fir_comp_ipc(struct test_data *td) { struct sof_ipc_comp_process *ipc; - struct sof_eq_fir_config *eq; size_t ipc_size = sizeof(struct sof_ipc_comp_process); - struct sof_abi_hdr *blob = (struct sof_abi_hdr *)fir_coef_2ch; const struct sof_uuid uuid = SOF_REG_UUID(eq_fir); - ipc = calloc(1, ipc_size + blob->size + SOF_UUID_SIZE); + ipc = calloc(1, ipc_size + SOF_UUID_SIZE); memcpy_s(ipc + 1, SOF_UUID_SIZE, &uuid, SOF_UUID_SIZE); - eq = (struct sof_eq_fir_config *)((char *)(ipc + 1) + SOF_UUID_SIZE); ipc->comp.hdr.size = ipc_size + SOF_UUID_SIZE; ipc->comp.type = SOF_COMP_MODULE_ADAPTER; ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); - ipc->size = blob->size; + ipc->size = 0; ipc->comp.ext_data_length = SOF_UUID_SIZE; - memcpy_s(eq, blob->size, blob->data, blob->size); return ipc; } +static int eq_fir_send_config(struct processing_module *mod) +{ + const struct module_interface *const ops = mod->dev->drv->adapter_ops; + struct sof_abi_hdr *blob = (struct sof_abi_hdr *)fir_coef_2ch; + size_t cdata_size = sizeof(struct sof_ipc_ctrl_data) + + sizeof(struct sof_abi_hdr) + blob->size; + struct sof_ipc_ctrl_data *cdata; + int ret; + + cdata = calloc(1, cdata_size); + if (!cdata) + return -ENOMEM; + + cdata->cmd = SOF_CTRL_CMD_BINARY; + cdata->num_elems = blob->size; + cdata->data[0].magic = blob->magic; + cdata->data[0].type = blob->type; + cdata->data[0].size = blob->size; + cdata->data[0].abi = blob->abi; + memcpy_s(cdata->data[0].data, blob->size, blob->data, blob->size); + + ret = ops->set_configuration(mod, 0, MODULE_CFG_FRAGMENT_SINGLE, + blob->size, (const uint8_t *)cdata, + blob->size, NULL, 0); + + free(cdata); + return ret; +} + static void prepare_sink(struct test_data *td, struct processing_module *mod) { struct test_parameters *parameters = td->params; @@ -156,6 +182,10 @@ static int setup(void **state) dev->frames = params->frames; mod = comp_mod(dev); + ret = eq_fir_send_config(mod); + if (ret) + return ret; + prepare_sink(td, mod); prepare_source(td, mod); diff --git a/test/cmocka/src/audio/eq_iir/eq_iir_process.c b/test/cmocka/src/audio/eq_iir/eq_iir_process.c index 9df4d17af864..756a4606c68b 100644 --- a/test/cmocka/src/audio/eq_iir/eq_iir_process.c +++ b/test/cmocka/src/audio/eq_iir/eq_iir_process.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "../../util.h" #include "../../../include/cmocka_chirp_2ch.h" @@ -68,23 +69,48 @@ static int setup_group(void **state) static struct sof_ipc_comp_process *create_eq_iir_comp_ipc(struct test_data *td) { struct sof_ipc_comp_process *ipc; - struct sof_eq_iir_config *eq; size_t ipc_size = sizeof(struct sof_ipc_comp_process); - struct sof_abi_hdr *blob = (struct sof_abi_hdr *)iir_coef_2ch; const struct sof_uuid uuid = SOF_REG_UUID(eq_iir); - ipc = calloc(1, ipc_size + blob->size + SOF_UUID_SIZE); + ipc = calloc(1, ipc_size + SOF_UUID_SIZE); memcpy_s(ipc + 1, SOF_UUID_SIZE, &uuid, SOF_UUID_SIZE); - eq = (struct sof_eq_iir_config *)((char *)(ipc + 1) + SOF_UUID_SIZE); ipc->comp.hdr.size = ipc_size + SOF_UUID_SIZE; ipc->comp.type = SOF_COMP_MODULE_ADAPTER; ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); - ipc->size = blob->size; + ipc->size = 0; ipc->comp.ext_data_length = SOF_UUID_SIZE; - memcpy_s(eq, blob->size, blob->data, blob->size); return ipc; } +static int eq_iir_send_config(struct processing_module *mod) +{ + const struct module_interface *const ops = mod->dev->drv->adapter_ops; + struct sof_abi_hdr *blob = (struct sof_abi_hdr *)iir_coef_2ch; + size_t cdata_size = sizeof(struct sof_ipc_ctrl_data) + sizeof(struct sof_abi_hdr) + + blob->size; + struct sof_ipc_ctrl_data *cdata; + int ret; + + cdata = calloc(1, cdata_size); + if (!cdata) + return -ENOMEM; + + cdata->cmd = SOF_CTRL_CMD_BINARY; + cdata->num_elems = blob->size; + cdata->data[0].magic = blob->magic; + cdata->data[0].type = blob->type; + cdata->data[0].size = blob->size; + cdata->data[0].abi = blob->abi; + memcpy_s(cdata->data[0].data, blob->size, blob->data, blob->size); + + ret = ops->set_configuration(mod, 0, MODULE_CFG_FRAGMENT_SINGLE, + blob->size, (const uint8_t *)cdata, + blob->size, NULL, 0); + + free(cdata); + return ret; +} + static void prepare_sink(struct test_data *td, struct processing_module *mod) { struct test_parameters *parameters = td->params; @@ -155,6 +181,10 @@ static int setup(void **state) dev->frames = params->frames; mod = comp_mod(dev); + ret = eq_iir_send_config(mod); + if (ret) + return ret; + prepare_sink(td, mod); prepare_source(td, mod); diff --git a/tools/testbench/topology_ipc4.c b/tools/testbench/topology_ipc4.c index 5917da8cb64e..9c4900f92fed 100644 --- a/tools/testbench/topology_ipc4.c +++ b/tools/testbench/topology_ipc4.c @@ -1286,6 +1286,7 @@ static int tb_kcontrol_cb_new(struct snd_soc_tplg_ctl_hdr *tplg_ctl, struct snd_soc_tplg_mixer_control *tplg_mixer; struct snd_soc_tplg_enum_control *tplg_enum; struct snd_soc_tplg_bytes_control *tplg_bytes; + struct sof_abi_hdr *abi; if (glb->num_ctls >= TB_MAX_CTLS) { fprintf(stderr, "Error: Too many controls already.\n"); @@ -1358,7 +1359,26 @@ static int tb_kcontrol_cb_new(struct snd_soc_tplg_ctl_hdr *tplg_ctl, tplg_bytes->priv.size); return -EINVAL; } - ctl->data = tplg_bytes->priv.data; + + if (tplg_bytes->priv.size >= sizeof(struct sof_abi_hdr)) { + abi = (struct sof_abi_hdr *)tplg_bytes->priv.data; + if (abi->size > TB_MAX_BYTES_DATA_SIZE) { + fprintf(stderr, + "Error: ABI payload size %u exceeds max %d\n", + abi->size, TB_MAX_BYTES_DATA_SIZE); + return -EINVAL; + } + if (tplg_bytes->priv.size < + sizeof(struct sof_abi_hdr) + abi->size) { + fprintf(stderr, + "Error: bytes data size %d is smaller than ABI header + payload (%zu + %u)\n", + tplg_bytes->priv.size, + sizeof(struct sof_abi_hdr), abi->size); + return -EINVAL; + } + ctl->data = tplg_bytes->priv.data; + } + ctl->comp_info = comp_info; strncpy(ctl->name, tplg_ctl->name, TB_MAX_CTL_NAME_CHARS); break; diff --git a/tools/testbench/utils_ipc4.c b/tools/testbench/utils_ipc4.c index 97b50ecd6c31..00449de3bbd3 100644 --- a/tools/testbench/utils_ipc4.c +++ b/tools/testbench/utils_ipc4.c @@ -290,7 +290,8 @@ static int tb_set_up_widget(struct testbench_prm *tp, struct tplg_comp_info *com /* send the bytes data from kcontrols associated with current widget */ if (ctl->module_id != comp_info->module_id || ctl->instance_id != comp_info->instance_id || - ctl->type != SND_SOC_TPLG_TYPE_BYTES) + ctl->type != SND_SOC_TPLG_TYPE_BYTES || + !ctl->data) continue; abi = (struct sof_abi_hdr *)ctl->data;