From cff23f5c4e169c8d17b8aac86ab256990f610ca6 Mon Sep 17 00:00:00 2001 From: Serhiy Katsyuba Date: Thu, 27 Jul 2023 17:34:34 +0200 Subject: [PATCH] Fix panic upon cancelling not scheduled task Calling zephyr_ll_task_cancel() for a task which was actually never scheduled results later in panic in zephyr_ll_task_done(). The fix makes zephyr_ll_task_cancel() do nothing for tasks which were only initialized but never scheduled. Signed-off-by: Serhiy Katsyuba --- src/schedule/zephyr_ll.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/schedule/zephyr_ll.c b/src/schedule/zephyr_ll.c index 7405dc0b22a9..06608d188873 100644 --- a/src/schedule/zephyr_ll.c +++ b/src/schedule/zephyr_ll.c @@ -436,11 +436,18 @@ static int zephyr_ll_task_cancel(void *data, struct task *task) * kept atomic, so we have to lock here too. */ zephyr_ll_lock(sch, &flags); - if (task->state != SOF_TASK_STATE_FREE) { + + /* + * SOF_TASK_STATE_CANCEL can only be assigned to a task which is on scheduler's list. + * Later such task will be removed from the list by zephyr_ll_task_done(). Do nothing + * for tasks which were never scheduled or were already removed from scheduler's list. + */ + if (task->state != SOF_TASK_STATE_INIT && task->state != SOF_TASK_STATE_FREE) { task->state = SOF_TASK_STATE_CANCEL; /* let domain know that a task has been cancelled */ domain_task_cancel(sch->ll_domain, task); } + zephyr_ll_unlock(sch, &flags); return 0;