]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
printk: Flush console on unregister_console()
authorJohn Ogness <john.ogness@linutronix.de>
Wed, 4 Sep 2024 12:05:22 +0000 (14:11 +0206)
committerPetr Mladek <pmladek@suse.com>
Wed, 4 Sep 2024 13:56:32 +0000 (15:56 +0200)
Ensure consoles have flushed pending records before
unregistering. The console should print up to at least its
related "console disabled" record.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20240904120536.115780-4-john.ogness@linutronix.de
Signed-off-by: Petr Mladek <pmladek@suse.com>
kernel/printk/printk.c

index acf668001096a63ab0f033e6c184985317f5c30a..c79e962b822ad59c1dc34245457843aab2935855 100644 (file)
@@ -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