From 0e724e3d5d5229b2316e878a5861b7ef07618ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Wed, 28 Aug 2019 18:09:05 +0200 Subject: [PATCH] cpu/fe310: don't call thread_yield when sched_active_thread is invalid As the comment above cpu_switch_context_exit notes: sched_active_thread is not valid when cpu_switch_context_exit() is called. Unfortunately, thread_yield(), which is called directly by cpu_switch_context_exit(), uses sched_active_thread possibly resulting in a null pointer dereference. Solution: Trigger a software interrupt to perform a context switch and let sched_run() determine the next valid thread from there. --- cpu/fe310/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpu/fe310/cpu.c b/cpu/fe310/cpu.c index b8e12ec446..f7cedd178e 100644 --- a/cpu/fe310/cpu.c +++ b/cpu/fe310/cpu.c @@ -334,8 +334,8 @@ void cpu_switch_context_exit(void) /* enable interrupts */ irq_enable(); - /* start the thread */ - thread_yield(); + /* start the thread by triggering a context switch */ + thread_yield_higher(); UNREACHABLE(); }