Skip to content

Commit d24e307

Browse files
committed
audio: kpb: clean up FMT module list on prepare failure
prepare_fmt_modules_list() populates kpb_list_item[], device_list[] and modules_list_item[] entries as it walks the module list. On any mid-loop failure it returned without undoing those entries, while the caller had already cleared the previous list, leaving a half-configured Fast Mode Task list with stale component references. Roll back the touched entries via clear_fmt_modules_list() on the error path, and add a defensive bound check on outpin_idx. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
1 parent 91e8d78 commit d24e307

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/audio/kpb.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,32 +2561,42 @@ static int prepare_fmt_modules_list(struct comp_dev *kpb_dev,
25612561
struct kpb_fmt_dev_list *fmt_device_list =
25622562
&((struct comp_data *)comp_get_drvdata(kpb_dev))->fmt_device_list;
25632563

2564+
if (outpin_idx >= KPB_MAX_SINK_CNT)
2565+
return -EINVAL;
2566+
25642567
fmt_device_list->kpb_list_item[outpin_idx] = kpb_dev;
25652568
ret = devicelist_push(&fmt_device_list->device_list[outpin_idx],
25662569
&fmt_device_list->kpb_list_item[outpin_idx]);
25672570
if (ret < 0)
2568-
return ret;
2571+
goto err;
25692572

25702573
for (size_t mod_idx = 0; mod_idx < modules_to_prepare->number_of_modules; ++mod_idx) {
25712574
uint32_t comp_id = IPC4_COMP_ID(modules_to_prepare->dev_ids[mod_idx].module_id,
25722575
modules_to_prepare->dev_ids[mod_idx].instance_id);
25732576

25742577
dev = ipc4_get_comp_dev(comp_id);
2575-
if (!dev)
2576-
return -EINVAL;
2578+
if (!dev) {
2579+
ret = -EINVAL;
2580+
goto err;
2581+
}
25772582

25782583
struct comp_dev **new_list_item_ptr;
25792584

25802585
ret = alloc_fmt_module_list_item(fmt_device_list, dev, &new_list_item_ptr);
25812586
if (ret < 0)
2582-
return ret;
2587+
goto err;
25832588
*new_list_item_ptr = dev;
25842589
ret = devicelist_push(&fmt_device_list->device_list[outpin_idx],
25852590
new_list_item_ptr);
25862591
if (ret < 0)
2587-
return ret;
2592+
goto err;
25882593
}
25892594
return 0;
2595+
2596+
err:
2597+
/* drop any entries pushed so far to avoid leaving a half-configured list */
2598+
clear_fmt_modules_list(fmt_device_list, outpin_idx);
2599+
return ret;
25902600
}
25912601

25922602
static int clear_fmt_modules_list(struct kpb_fmt_dev_list *fmt_device_list,

0 commit comments

Comments
 (0)