Skip to content

Commit 1236f9d

Browse files
andyrosscujomalainey
authored andcommitted
IPC4: Handle duplicate component IDs
In the SOF scheme, component IDs are allocated by the host driver. So they need to be validated before use when modifying the global component list to prevent duplicate entries from being inserted. IPC3 was doing this already. IPC4 had copied the form of the code in one spot, but had missed that the ID is global across types and was only checking for duplicate pipelines. Signed-off-by: Andy Ross <andyross@google.com>
1 parent 320a932 commit 1236f9d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ipc/ipc4/helper.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,9 @@ static int ipc4_create_pipeline(struct ipc4_pipeline_create *pipe_desc)
178178
struct ipc *ipc = ipc_get();
179179

180180
/* check whether pipeline id is already taken or in use */
181-
ipc_pipe = ipc_get_comp_by_ppl_id(ipc, COMP_TYPE_PIPELINE,
182-
pipe_desc->primary.r.instance_id);
181+
ipc_pipe = ipc_get_comp_by_id(ipc, pipe_desc->primary.r.instance_id);
183182
if (ipc_pipe) {
184-
tr_err(&ipc_tr, "ipc: pipeline id is already taken, pipe_desc->instance_id = %u",
183+
tr_err(&ipc_tr, "ipc: comp id is already taken, pipe_desc->instance_id = %u",
185184
(uint32_t)pipe_desc->primary.r.instance_id);
186185
return IPC4_INVALID_RESOURCE_ID;
187186
}
@@ -748,6 +747,13 @@ int ipc4_add_comp_dev(struct comp_dev *dev)
748747
struct ipc *ipc = ipc_get();
749748
struct ipc_comp_dev *icd;
750749

750+
/* check id for duplicates */
751+
icd = ipc_get_comp_by_id(ipc, dev->ipc_config.id);
752+
if (icd) {
753+
tr_err(&ipc_tr, "ipc: duplicate component ID");
754+
return IPC4_INVALID_RESOURCE_ID;
755+
}
756+
751757
/* allocate the IPC component container */
752758
icd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM,
753759
sizeof(struct ipc_comp_dev));

0 commit comments

Comments
 (0)