]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
printk/console: Split out code that enables default console
authorPetr Mladek <pmladek@suse.com>
Mon, 22 Nov 2021 13:26:45 +0000 (14:26 +0100)
committerPetr Mladek <pmladek@suse.com>
Mon, 6 Dec 2021 13:07:57 +0000 (14:07 +0100)
Put the code enabling a console by default into a separate function
called try_enable_default_console().

Rename try_enable_new_console() to try_enable_preferred_console() to
make the purpose of the different variants more clear.

It is a code refactoring without any functional change.

Signed-off-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Link: https://lore.kernel.org/r/20211122132649.12737-2-pmladek@suse.com
kernel/printk/printk.c

index 57b132b658e155b7344d44f9e930039080941290..1acbe39dd47ceea028aff4536b91c910a83b47ca 100644 (file)
@@ -2861,7 +2861,8 @@ early_param("keep_bootcon", keep_bootcon_setup);
  * Care need to be taken with consoles that are statically
  * enabled such as netconsole
  */
-static int try_enable_new_console(struct console *newcon, bool user_specified)
+static int try_enable_preferred_console(struct console *newcon,
+                                       bool user_specified)
 {
        struct console_cmdline *c;
        int i, err;
@@ -2909,6 +2910,23 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
        return -ENOENT;
 }
 
+/* Try to enable the console unconditionally */
+static void try_enable_default_console(struct console *newcon)
+{
+       if (newcon->index < 0)
+               newcon->index = 0;
+
+       if (newcon->setup && newcon->setup(newcon, NULL) != 0)
+               return;
+
+       newcon->flags |= CON_ENABLED;
+
+       if (newcon->device) {
+               newcon->flags |= CON_CONSDEV;
+               has_preferred_console = true;
+       }
+}
+
 /*
  * The console driver calls this routine during kernel initialization
  * to register the console printing procedure with printk() and to
@@ -2964,25 +2982,15 @@ void register_console(struct console *newcon)
         *      didn't select a console we take the first one
         *      that registers here.
         */
-       if (!has_preferred_console) {
-               if (newcon->index < 0)
-                       newcon->index = 0;
-               if (newcon->setup == NULL ||
-                   newcon->setup(newcon, NULL) == 0) {
-                       newcon->flags |= CON_ENABLED;
-                       if (newcon->device) {
-                               newcon->flags |= CON_CONSDEV;
-                               has_preferred_console = true;
-                       }
-               }
-       }
+       if (!has_preferred_console)
+               try_enable_default_console(newcon);
 
        /* See if this console matches one we selected on the command line */
-       err = try_enable_new_console(newcon, true);
+       err = try_enable_preferred_console(newcon, true);
 
        /* If not, try to match against the platform default(s) */
        if (err == -ENOENT)
-               err = try_enable_new_console(newcon, false);
+               err = try_enable_preferred_console(newcon, false);
 
        /* printk() messages are not printed to the Braille console. */
        if (err || newcon->flags & CON_BRL)