From 000138e6c1558b89b4e052966c303e08efcf2c14 Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Wed, 14 Jul 2021 11:44:51 -0600 Subject: lib/thread: Verify threads are initialized before yielding In hardwaremain.c we call console_init before threads_initialize. Part of setting up the uart requires calling udelay which then calls thread_yield_microseconds. Since threads have not been set up, trying to yield will result in bad things happening. This change guards the thread methods by making current_thread return NULL if the structures have not been initialized. BUG=b:179699789 TEST=Ramstage no longer hangs with serial enabled Signed-off-by: Raul E Rangel Change-Id: If9e1eedfaebe584901d2937c8aa24e158706fa43 Reviewed-on: https://review.coreboot.org/c/coreboot/+/56318 Reviewed-by: Krystian Hebel Reviewed-by: Julius Werner Reviewed-by: Karthik Ramasubramanian Reviewed-by: Furquan Shaikh Tested-by: build bot (Jenkins) --- src/lib/thread.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib/thread.c') diff --git a/src/lib/thread.c b/src/lib/thread.c index e2280c63fe..782a63ea52 100644 --- a/src/lib/thread.c +++ b/src/lib/thread.c @@ -9,6 +9,8 @@ #include #include +static bool initialized; + static void idle_thread_init(void); /* There needs to be at least one thread to run the ramstate state machine. */ @@ -40,6 +42,9 @@ static inline struct thread *cpu_info_to_thread(const struct cpu_info *ci) static inline struct thread *current_thread(void) { + if (!initialized) + return NULL; + return cpu_info_to_thread(cpu_info()); } @@ -265,6 +270,8 @@ void threads_initialize(void) free_thread(t); } + initialized = 1; + idle_thread_init(); } -- cgit v1.2.3