rtnr: refine set/get component data procedure

This commit refines the following procedures to
make it more stable on different platforms.

1.  The initial data( not config ) defined in the topology
is empty. On some platforms rtnr_get_comp_data
might be called with the size equals 0 during
initialization. We only do the memcpy_s when the size
is valid.

2. There are 3 control widgets in RTNR topology. During
initialization, the initial data could be received via IPC
in the form of config+data+switch or config only. In
either case we now just copy the preceding portion
of the data since it has the required config.

Signed-off-by: Ming Jen Tai <mingjen_tai@realtek.com>
This commit is contained in:
Ming Jen Tai 2022-10-25 13:33:00 +08:00 committed by Liam Girdwood
parent 7029fb7b01
commit 4a438b962b
1 changed files with 33 additions and 56 deletions

View File

@ -65,8 +65,8 @@ DECLARE_TR_CTX(rtnr_tr, SOF_UUID(rtnr_uuid), LOG_LEVEL_INFO);
/* Generic processing */ /* Generic processing */
/* Static functions */ /* Static functions */
static int rtnr_set_comp_config_by_ipc_config_process(struct comp_dev *dev, static int rtnr_set_config_bytes(struct comp_dev *dev,
struct ipc_config_process *ipc_config); unsigned char *data, uint32_t size);
/* Called by the processing library for debugging purpose */ /* Called by the processing library for debugging purpose */
void rtnr_printf(int a, int b, int c, int d, int e) void rtnr_printf(int a, int b, int c, int d, int e)
@ -261,7 +261,7 @@ static struct comp_dev *rtnr_new(const struct comp_driver *drv,
} }
/* Get initial configuration from topology */ /* Get initial configuration from topology */
ret = rtnr_set_comp_config_by_ipc_config_process(dev, ipc_rtnr); ret = rtnr_set_config_bytes(dev, ipc_rtnr->data, ipc_rtnr->size);
if (ret < 0) { if (ret < 0) {
comp_cl_err(&comp_rtnr, "rtnr_new(): failed setting initial config"); comp_cl_err(&comp_rtnr, "rtnr_new(): failed setting initial config");
goto cd_fail; goto cd_fail;
@ -423,12 +423,16 @@ static int rtnr_get_comp_data(struct comp_data *cd, struct sof_ipc_ctrl_data *cd
if (size > max_data_size || size < 0) if (size > max_data_size || size < 0)
return -EINVAL; return -EINVAL;
ret = memcpy_s(cdata->data->data, if (size > 0) {
max_data_size, ret = memcpy_s(cdata->data->data,
config, max_data_size,
size); config,
if (ret) size);
return ret; comp_cl_info(&comp_rtnr, "rtnr_get_comp_data(): size= %d, ret = %d",
size, ret);
if (ret)
return ret;
}
cdata->data->abi = SOF_ABI_VERSION; cdata->data->abi = SOF_ABI_VERSION;
cdata->data->size = size; cdata->data->size = size;
@ -510,62 +514,33 @@ static int rtnr_reconfigure(struct comp_dev *dev)
return 0; return 0;
} }
static int rtnr_set_comp_config_by_ipc_config_process(struct comp_dev *dev, static int rtnr_set_config_bytes(struct comp_dev *dev,
struct ipc_config_process *config) unsigned char *data, uint32_t size)
{ {
struct comp_data *cd = comp_get_drvdata(dev); struct comp_data *cd = comp_get_drvdata(dev);
int ret; int ret;
comp_dbg(dev, "rtnr_set_comp_config_by_ipc_config(): %d", config->size); /*
if (config->size != sizeof(cd->config)) { * The received data could be the combined blob of the control
comp_err(dev, "rtnr_set_comp_config_by_ipc_config(): invalid size %d", * widgets defined in the topology, or the config received by
config->size); * SOF_CTRL_CMD_BINARY. In either case we just have to check if
* the whole config data is received.
*/
if (size < sizeof(cd->config)) {
comp_err(dev, "rtnr_set_config_data(): invalid size %d",
size);
return -EINVAL; return -EINVAL;
} }
ret = memcpy_s(&cd->config, ret = memcpy_s(&cd->config,
sizeof(cd->config), sizeof(cd->config),
config->data, data,
config->size); sizeof(cd->config));
if (ret)
return ret;
comp_info(dev, comp_info(dev,
"rtnr_set_comp_config_by_ipc_config(): sample_rate = %d, enabled=%d", "rtnr_set_config_data(): sample_rate = %d, enabled=%d",
cd->config.params.sample_rate, cd->config.params.sample_rate,
cd->config.params.enabled); cd->config.params.enabled);
return ret;
}
static int rtnr_set_comp_config_by_ipc_ctrl_data(struct comp_dev *dev,
struct sof_ipc_ctrl_data *cdata)
{
struct comp_data *cd = comp_get_drvdata(dev);
int ret;
comp_dbg(dev, "rtnr_set_comp_config_by_ipc_ctrl_data(): size: %d",
cdata->data->size);
if (cdata->data->size != sizeof(cd->config)) {
comp_err(dev,
"rtnr_set_comp_config_by_ipc_ctrl_data(): invalid size %d",
cdata->data->size);
return -EINVAL;
}
ret = memcpy_s(&cd->config,
sizeof(cd->config),
cdata->data->data,
cdata->data->size);
if (ret)
return ret;
comp_info(dev,
"rtnr_set_comp_config_by_ipc_ctrl_data(): sample_rate = %d, enabled=%d",
cd->config.params.sample_rate,
cd->config.params.enabled);
return ret; return ret;
} }
@ -586,7 +561,9 @@ static int rtnr_set_bin_data(struct comp_dev *dev, struct sof_ipc_ctrl_data *cda
switch (cdata->data->type) { switch (cdata->data->type) {
case SOF_RTNR_CONFIG: case SOF_RTNR_CONFIG:
return rtnr_set_comp_config_by_ipc_ctrl_data(dev, cdata); return rtnr_set_config_bytes(dev,
(unsigned char *)cdata->data->data,
cdata->data->size);
case SOF_RTNR_DATA: case SOF_RTNR_DATA:
ret = comp_data_blob_set_cmd(cd->model_handler, cdata); ret = comp_data_blob_set_cmd(cd->model_handler, cdata);
if (ret) if (ret)