Skip to content

Commit a695337

Browse files
committed
printk/console: Rename has_preferred_console to need_default_console
The logic around the variable @has_preferred_console made my head spin many times. Part of the problem is the ambiguous name. There is the variable @preferred_console. It points to the last non-braille console in @console_cmdline array. This array contains consoles preferred via the command line, device tree, or SPCR. Then there is the variable @has_preferred_console. It is set to "true" when @preferred_console is enabled or when a console with tty binding gets enabled by default. It might get reset back by the magic condition: if (!has_preferred_console || bcon || !console_drivers) has_preferred_console = preferred_console >= 0; It is a puzzle. Dumb explanation is that it gets re-evaluated when: + it was not set before (see above when it gets set) + there is still an early console enabled (bcon) + there is no console enabled (!console_drivers) This is still a puzzle. It gets more clear when we see where the value is checked. The only meaning of the variable is to decide whether we should try to enable the new console by default. Rename the variable according to the single situation where the value is checked. The rename requires an inverted logic. Otherwise, it is a simple search & replace. It does not change the functionality. Signed-off-by: Petr Mladek <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ed758b3 commit a695337

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kernel/printk/printk.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static struct console *exclusive_console;
280280
static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
281281

282282
static int preferred_console = -1;
283-
static bool has_preferred_console;
283+
static bool need_default_console = true;
284284
int console_set_on_cmdline;
285285
EXPORT_SYMBOL(console_set_on_cmdline);
286286

@@ -2894,7 +2894,7 @@ static int try_enable_preferred_console(struct console *newcon,
28942894
newcon->flags |= CON_ENABLED;
28952895
if (i == preferred_console) {
28962896
newcon->flags |= CON_CONSDEV;
2897-
has_preferred_console = true;
2897+
need_default_console = false;
28982898
}
28992899
return 0;
29002900
}
@@ -2923,7 +2923,7 @@ static void try_enable_default_console(struct console *newcon)
29232923

29242924
if (newcon->device) {
29252925
newcon->flags |= CON_CONSDEV;
2926-
has_preferred_console = true;
2926+
need_default_console = false;
29272927
}
29282928
}
29292929

@@ -2974,15 +2974,15 @@ void register_console(struct console *newcon)
29742974
if (console_drivers && console_drivers->flags & CON_BOOT)
29752975
bcon = console_drivers;
29762976

2977-
if (!has_preferred_console || bcon || !console_drivers)
2978-
has_preferred_console = preferred_console >= 0;
2977+
if (need_default_console || bcon || !console_drivers)
2978+
need_default_console = preferred_console < 0;
29792979

29802980
/*
29812981
* See if we want to use this console driver. If we
29822982
* didn't select a console we take the first one
29832983
* that registers here.
29842984
*/
2985-
if (!has_preferred_console)
2985+
if (need_default_console)
29862986
try_enable_default_console(newcon);
29872987

29882988
/* See if this console matches one we selected on the command line */

0 commit comments

Comments
 (0)