lib: sbi: protect dprintf output with spinlock
authorDong Du <Dd_nirvana@sjtu.edu.cn>
Sat, 28 Aug 2021 06:45:02 +0000 (14:45 +0800)
committerAnup Patel <anup@brainfault.org>
Mon, 30 Aug 2021 03:42:37 +0000 (09:12 +0530)
Avoid getting messages from multiple harts (using dprintf and printf)
concurrently with a spinlock serializaing calls to sbi_dprintf(),
sbi_printf() and sbi_puts()

Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
lib/sbi/sbi_console.c

index b54f7a2..29eede3 100644 (file)
@@ -387,8 +387,11 @@ int sbi_dprintf(const char *format, ...)
        struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 
        va_start(args, format);
-       if (scratch->options & SBI_SCRATCH_DEBUG_PRINTS)
+       if (scratch->options & SBI_SCRATCH_DEBUG_PRINTS) {
+               spin_lock(&console_out_lock);
                retval = print(NULL, NULL, format, args);
+               spin_unlock(&console_out_lock);
+       }
        va_end(args);
 
        return retval;