diff options
author | Raul E Rangel <rrangel@chromium.org> | 2021-07-14 11:44:51 -0600 |
---|---|---|
committer | Raul Rangel <rrangel@chromium.org> | 2021-07-15 21:50:27 +0000 |
commit | 000138e6c1558b89b4e052966c303e08efcf2c14 (patch) | |
tree | 89d8a921e1adf12152da1d5c7545c29c6d686fb8 /src/lib | |
parent | 577e146895d489d809b4d41da7f6f2d7428143a2 (diff) |
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 <rrangel@chromium.org>
Change-Id: If9e1eedfaebe584901d2937c8aa24e158706fa43
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56318
Reviewed-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Reviewed-by: Furquan Shaikh <furquan@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/thread.c | 7 |
1 files changed, 7 insertions, 0 deletions
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 <thread.h> #include <timer.h> +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(); } |