diff --git a/src/schedule/zephyr_dp_schedule_application.c b/src/schedule/zephyr_dp_schedule_application.c index e1d34f0458c8..226c86ba4c9e 100644 --- a/src/schedule/zephyr_dp_schedule_application.c +++ b/src/schedule/zephyr_dp_schedule_application.c @@ -478,6 +478,8 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid, memset(task_memory, 0, sizeof(*task_memory)); + const struct comp_driver *drv = mod->dev->drv; + task_memory->drv = *mod->dev->drv; mod->dev->drv = &task_memory->drv; @@ -526,7 +528,6 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid, ptask->ops.get_deadline = ops->get_deadline; ptask->priv_data = pdata; list_init(&ptask->list); - *task = ptask; /* create a zephyr thread for the task */ pdata->thread_id = k_thread_create(pdata->thread, p_stack, @@ -627,6 +628,9 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid, k_event_init(pdata->event); k_thread_start(pdata->thread_id); + /* ptask points into task_memory, so only publish it once it cannot be freed */ + *task = ptask; + return 0; e_dom: @@ -643,6 +647,8 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid, e_stack: user_stack_free(p_stack); e_tmem: + /* the copy lives in task_memory, so stop pointing at it before freeing */ + mod->dev->drv = drv; mod_free(mod, task_memory); return ret; }