From 3a1b5ec3dd91bac4833167cedcd68d9d4936ce6b Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 27 Jan 2015 14:18:23 -0800 Subject: [PATCH] cortex-m: disallow rescheduling if task_start() has not yet run Most GPIO/peripheral interrupts are enabled in HOOK_INIT or some other *_init() functions that are called before task_start(). Quite a lot of these IRQ handler wake some task to process the interrupt, and this causes a race condition. If the interrupt is triggered before task_start() is called, the system may crash/hang/whatever. Fix this by only allowing rescheduling tasks if task_start() is called. This is basically the cortex-m version of commit e541eeb2. BRANCH=Ryu BUG=None TEST=Without this fix, my Ryu P3 always crashes when cold resetting from bootloader mode. After applying this fix, it doesn't anymore. Change-Id: I0f81e90482ff97469c4f0423d6aa060f2ac76f74 Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/243626 Tested-by: Vic Yang Reviewed-by: Alec Berg Commit-Queue: Vic Yang --- core/cortex-m/task.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c index b90f91ce00..69e93457cb 100644 --- a/core/cortex-m/task.c +++ b/core/cortex-m/task.c @@ -359,7 +359,8 @@ uint32_t task_set_event(task_id_t tskid, uint32_t event, int wait) /* The receiver might run again */ atomic_or(&tasks_ready, 1 << tskid); #ifndef CONFIG_TASK_PROFILING - need_resched_or_profiling = 1; + if (start_called) + need_resched_or_profiling = 1; #endif } else { if (wait)