Angel Pons has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/49942 )
Change subject: console/printk.c: Prevent recursion in print functions ......................................................................
console/printk.c: Prevent recursion in print functions
Exit early if calling a print function from within another print function. Otherwise, infinite recursion can and will happen.
Change-Id: I742e4087bffa64897e9ffa47531d37e42fb2c63e Signed-off-by: Angel Pons th3fanbus@gmail.com --- M src/console/printk.c 1 file changed, 17 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/42/49942/1
diff --git a/src/console/printk.c b/src/console/printk.c index 85d9bfb..8822009c 100644 --- a/src/console/printk.c +++ b/src/console/printk.c @@ -19,6 +19,9 @@ static struct mono_time mt_start, mt_stop; static long console_usecs;
+/* Prevent recursion in print functions */ +static int recursion_depth; + static void console_time_run(void) { if (TRACK_CONSOLE_TIME && boot_cpu()) @@ -54,9 +57,16 @@
void do_putchar(unsigned char byte) { + if (recursion_depth) + return; + + recursion_depth++; + console_time_run(); console_tx_byte(byte); console_time_stop(); + + recursion_depth--; }
static void wrap_putchar(unsigned char byte, void *data) @@ -80,6 +90,11 @@ if (log_this < CONSOLE_LOG_FAST) return 0;
+ if (recursion_depth) + return 0; + + recursion_depth++; + spin_lock(&console_lock);
console_time_run(); @@ -95,6 +110,8 @@
spin_unlock(&console_lock);
+ recursion_depth--; + return i; }