Subject: [PATCH 21/24] printk: only disable if actually unregistered
From: John Ogness <[email-masked]>
Date: Tue, 7 Mar 2023 18:22:26 +0000

Currently in unregister_console() a printk message is generated and
the console is disabled, even it was never registered. There are
code paths (such as uart_remove_one_port()) that call
unregister_console() even if the console is not registered.

It is confusing to see messages about consoles being disabled that
were never disabled. Move the printk and disabling later, when it
is known that the console is actually registered.

Signed-off-by: John Ogness <[email-masked]>
Signed-off-by: Sebastian Andrzej Siewior <[email-masked]>
---
 kernel/printk/printk.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Index: linux-6.3.0-rt11/kernel/printk/printk.c
===================================================================
--- linux-6.3.0-rt11.orig/kernel/printk/printk.c
+++ linux-6.3.0-rt11/kernel/printk/printk.c
@@ -3599,20 +3599,19 @@ static int unregister_console_locked(str
 
 	is_boot_con = console->flags & CON_BOOT;
 
-	con_printk(KERN_INFO, console, "disabled\n");
-
 	res = _braille_unregister_console(console);
 	if (res < 0)
 		return res;
 	if (res > 0)
 		return 0;
 
-	/* Disable it unconditionally */
-	console_srcu_write_flags(console, console->flags & ~CON_ENABLED);
-
 	if (!console_is_registered_locked(console))
 		return -ENODEV;
 
+	console_srcu_write_flags(console, console->flags & ~CON_ENABLED);
+
+	con_printk(KERN_INFO, console, "disabled\n");
+
 	hlist_del_init_rcu(&console->node);
 
 	/*