diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index acf668001096..c79e962b822a 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3771,11 +3771,16 @@ static int unregister_console_locked(struct console *console) if (res > 0) return 0; + if (!console_is_registered_locked(console)) + res = -ENODEV; + else if (console_is_usable(console, console->flags)) + __pr_flush(console, 1000, true); + /* Disable it unconditionally */ console_srcu_write_flags(console, console->flags & ~CON_ENABLED); - if (!console_is_registered_locked(console)) - return -ENODEV; + if (res < 0) + return res; /* * Use the driver synchronization to ensure that the hardware is not