Skip to content

Commit 4870dfc

Browse files
committed
module_adapter: dp: Add check for DP task creation error
Check the value returned by the pipeline_comp_dp_task_init() call in module_adapter_new_ext(). Update scheduler_dp_task_init() to assign the output task structure pointer only on success. The function allocates task structure and free it on failure. Returning a non-null task on error could lead to a double free in the module adapter or use after free. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent b5e48ed commit 4870dfc

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/audio/module_adapter/module_adapter.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
238238
/* create a task for DP processing */
239239
if (config->proc_domain == COMP_PROCESSING_DOMAIN_DP) {
240240
/* All data allocated, create a thread */
241-
pipeline_comp_dp_task_init(dev);
241+
ret = pipeline_comp_dp_task_init(dev);
242+
if (ret) {
243+
comp_cl_err(drv, "DP task creation failed with error %d.", ret);
244+
goto err;
245+
}
242246
}
243247
#endif /* CONFIG_ZEPHYR_DP_SCHEDULER */
244248

src/schedule/zephyr_dp_schedule_thread.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ int scheduler_dp_task_init(struct task **task,
262262
/* success, fill the structures */
263263
pdata->p_stack = p_stack;
264264
pdata->mod = mod;
265-
*task = &task_memory->task;
266265

267266
/* create a zephyr thread for the task */
268267
pdata->thread_id = k_thread_create(pdata->thread, (__sparse_force void *)p_stack,
269-
stack_size, dp_thread_fn, *task, NULL, NULL,
270-
CONFIG_DP_THREAD_PRIORITY, (*task)->flags, K_FOREVER);
268+
stack_size, dp_thread_fn, &task_memory->task, NULL, NULL,
269+
CONFIG_DP_THREAD_PRIORITY, task_memory->task.flags,
270+
K_FOREVER);
271271

272272
k_thread_access_grant(pdata->thread_id, pdata->event);
273273
scheduler_dp_grant(pdata->thread_id, cpu_get_id());
@@ -280,7 +280,7 @@ int scheduler_dp_task_init(struct task **task,
280280
}
281281

282282
#ifdef CONFIG_USERSPACE
283-
if ((*task)->flags & K_USER) {
283+
if (task_memory->task.flags & K_USER) {
284284
ret = user_memory_init_shared(pdata->thread_id, pdata->mod);
285285
if (ret < 0) {
286286
tr_err(&dp_tr, "user_memory_init_shared() failed");
@@ -293,6 +293,8 @@ int scheduler_dp_task_init(struct task **task,
293293
k_event_init(pdata->event);
294294
k_thread_start(pdata->thread_id);
295295

296+
/* success, fill output parameter */
297+
*task = &task_memory->task;
296298
return 0;
297299

298300
e_thread:

0 commit comments

Comments
 (0)