Skip to content

Commit ed758b3

Browse files
committed
printk/console: Split out code that enables default console
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 <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7d5775d commit ed758b3

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

kernel/printk/printk.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,7 +2861,8 @@ early_param("keep_bootcon", keep_bootcon_setup);
28612861
* Care need to be taken with consoles that are statically
28622862
* enabled such as netconsole
28632863
*/
2864-
static int try_enable_new_console(struct console *newcon, bool user_specified)
2864+
static int try_enable_preferred_console(struct console *newcon,
2865+
bool user_specified)
28652866
{
28662867
struct console_cmdline *c;
28672868
int i, err;
@@ -2909,6 +2910,23 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
29092910
return -ENOENT;
29102911
}
29112912

2913+
/* Try to enable the console unconditionally */
2914+
static void try_enable_default_console(struct console *newcon)
2915+
{
2916+
if (newcon->index < 0)
2917+
newcon->index = 0;
2918+
2919+
if (newcon->setup && newcon->setup(newcon, NULL) != 0)
2920+
return;
2921+
2922+
newcon->flags |= CON_ENABLED;
2923+
2924+
if (newcon->device) {
2925+
newcon->flags |= CON_CONSDEV;
2926+
has_preferred_console = true;
2927+
}
2928+
}
2929+
29122930
/*
29132931
* The console driver calls this routine during kernel initialization
29142932
* to register the console printing procedure with printk() and to
@@ -2964,25 +2982,15 @@ void register_console(struct console *newcon)
29642982
* didn't select a console we take the first one
29652983
* that registers here.
29662984
*/
2967-
if (!has_preferred_console) {
2968-
if (newcon->index < 0)
2969-
newcon->index = 0;
2970-
if (newcon->setup == NULL ||
2971-
newcon->setup(newcon, NULL) == 0) {
2972-
newcon->flags |= CON_ENABLED;
2973-
if (newcon->device) {
2974-
newcon->flags |= CON_CONSDEV;
2975-
has_preferred_console = true;
2976-
}
2977-
}
2978-
}
2985+
if (!has_preferred_console)
2986+
try_enable_default_console(newcon);
29792987

29802988
/* See if this console matches one we selected on the command line */
2981-
err = try_enable_new_console(newcon, true);
2989+
err = try_enable_preferred_console(newcon, true);
29822990

29832991
/* If not, try to match against the platform default(s) */
29842992
if (err == -ENOENT)
2985-
err = try_enable_new_console(newcon, false);
2993+
err = try_enable_preferred_console(newcon, false);
29862994

29872995
/* printk() messages are not printed to the Braille console. */
29882996
if (err || newcon->flags & CON_BRL)

0 commit comments

Comments
 (0)