Skip to content
Closed
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
32 changes: 31 additions & 1 deletion src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ static int copier_init(struct processing_module *mod)
struct module_data *md = &mod->priv;
struct ipc4_copier_module_cfg *copier = (struct ipc4_copier_module_cfg *)md->cfg.init_data;
struct comp_ipc_config *config = &dev->ipc_config;
void *gtw_cfg = NULL;
size_t gtw_cfg_size;
int i, ret = 0;

cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd));
Expand All @@ -78,7 +80,31 @@ static int copier_init(struct processing_module *mod)
*/
if (memcpy_s(&cd->config, sizeof(cd->config), copier, sizeof(*copier)) < 0) {
ret = -EINVAL;
goto error;
goto error_cd;
}

/* Allocate memory and store gateway_cfg in runtime. Gateway cfg has to
* be kept even after copier is created e.g. during SET_PIPELINE_STATE
* IPC when dai_config_dma_channel() is called second time and DMA
* config is used to assign dma_channel_id value.
*/
if (copier->gtw_cfg.config_length) {
gtw_cfg_size = copier->gtw_cfg.config_length << 2;
gtw_cfg = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
gtw_cfg_size);
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use rmalloc() - you overwrite it completely 5 lines later

if (!gtw_cfg) {
ret = -ENOMEM;
goto error_cd;
}

ret = memcpy_s(gtw_cfg, gtw_cfg_size, &copier->gtw_cfg.config_data,
gtw_cfg_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

why we can't directly copy data into cd->gtw_cfg with:

ret = memcpy_s(&cd->gtw_cfg, gtw_cfg_size, &copier->gtw_cfg.config_data,
gtw_cfg_size);

if (ret) {
comp_err(dev, "Unable to copy gateway config from copier blob");
goto error;
}

cd->gtw_cfg = gtw_cfg;
}

for (i = 0; i < IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT; i++)
Expand Down Expand Up @@ -148,6 +174,8 @@ static int copier_init(struct processing_module *mod)
dev->state = COMP_STATE_READY;
return 0;
error:
rfree(gtw_cfg);
error_cd:
rfree(cd);
return ret;
}
Expand All @@ -172,6 +200,8 @@ static int copier_free(struct processing_module *mod)
break;
}

if (cd)
rfree(cd->gtw_cfg);
rfree(cd);

return 0;
Expand Down
3 changes: 2 additions & 1 deletion src/audio/copier/copier.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct ipc4_copier_module_cfg {
/* audio format for output pin 0 */
struct ipc4_audio_format out_fmt;
uint32_t copier_feature_mask;
struct ipc4_copier_gateway_cfg gtw_cfg;
struct ipc4_copier_gateway_cfg gtw_cfg;
} __attribute__((packed, aligned(4)));

enum ipc4_copier_module_config_params {
Expand Down Expand Up @@ -242,6 +242,7 @@ struct copier_data {
* from the IPC data.
*/
struct ipc4_copier_module_cfg config;
void *gtw_cfg;
struct comp_dev *endpoint[IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT];
struct comp_buffer *endpoint_buffer[IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT];
uint32_t endpoint_num;
Expand Down