Skip to content

Commit 7dcbd90

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 a5116b9 commit 7dcbd90

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
@@ -2558,32 +2558,42 @@ static int prepare_fmt_modules_list(struct comp_dev *kpb_dev,
25582558
struct kpb_fmt_dev_list *fmt_device_list =
25592559
&((struct comp_data *)comp_get_drvdata(kpb_dev))->fmt_device_list;
25602560

2561+
if (outpin_idx >= KPB_MAX_SINK_CNT)
2562+
return -EINVAL;
2563+
25612564
fmt_device_list->kpb_list_item[outpin_idx] = kpb_dev;
25622565
ret = devicelist_push(&fmt_device_list->device_list[outpin_idx],
25632566
&fmt_device_list->kpb_list_item[outpin_idx]);
25642567
if (ret < 0)
2565-
return ret;
2568+
goto err;
25662569

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

25712574
dev = ipc4_get_comp_dev(comp_id);
2572-
if (!dev)
2573-
return -EINVAL;
2575+
if (!dev) {
2576+
ret = -EINVAL;
2577+
goto err;
2578+
}
25742579

25752580
struct comp_dev **new_list_item_ptr;
25762581

25772582
ret = alloc_fmt_module_list_item(fmt_device_list, dev, &new_list_item_ptr);
25782583
if (ret < 0)
2579-
return ret;
2584+
goto err;
25802585
*new_list_item_ptr = dev;
25812586
ret = devicelist_push(&fmt_device_list->device_list[outpin_idx],
25822587
new_list_item_ptr);
25832588
if (ret < 0)
2584-
return ret;
2589+
goto err;
25852590
}
25862591
return 0;
2592+
2593+
err:
2594+
/* drop any entries pushed so far to avoid leaving a half-configured list */
2595+
clear_fmt_modules_list(fmt_device_list, outpin_idx);
2596+
return ret;
25872597
}
25882598

25892599
static int clear_fmt_modules_list(struct kpb_fmt_dev_list *fmt_device_list,

0 commit comments

Comments
 (0)