Re: [PATCH 8/8] printk: Try enable preferred consoles only when there are any

From: Chris Down

Date: Thu Feb 19 2026 - 10:17:08 EST


Petr Mladek writes:
try_enable_preferred_console() used to be always called because it
had several hidden effects, namely:

- enabled Braille consoles which were ignored by "preferred_dev_console"
because they were not associated with /dev/console.

- returned success when a console was pre-enabled using CON_ENABLED
flag.

- returned success when a console was enabled by default because
try_enable_default_console() did not return success.

The first two hidden effects were removed in previous patches. Remove
the last one so that try_enable_preferred_console() can be called only
when any non-Braille console is preferred.

There is a fourth hidden effect that was also removed, unconditionally initialising err :-) Unfortunately removing that causes an uninitialised read.

@@ -4156,17 +4161,15 @@ void register_console(struct console *newcon)
if (preferred_dev_console < 0) {
if (hlist_empty(&console_list) || !console_first()->device ||
console_first()->flags & CON_BOOT) {
- try_enable_default_console(newcon);
+ err = try_enable_default_console(newcon);
}
+ } else {
+ err = try_enable_preferred_console(newcon, true);
+
+ if (err == -ENOENT)
+ err = try_enable_preferred_console(newcon, false);
}

When preferred_dev_console < 0 and the inner condition is false, nothing will initialise err.


- /* See if this console matches one we selected on the command line */
- err = try_enable_preferred_console(newcon, true);
-
- /* If not, try to match against the platform default(s) */
- if (err == -ENOENT)
- err = try_enable_preferred_console(newcon, false);

You can see previously it was initialised without conditions here.

Later we read err with `if (err == -ENOENT)`, so it's possible to do an uninitialised read.

Doing `int err = -ENOENT` at declaration should fix it by the look of it.