[PATCH v5 14/16] printk: Do not set Braille console as preferred_console

From: Petr Mladek

Date: Tue Sep 29 2026 - 08:12:05 EST


The Braille console reuses the framework for handling consoles preferred
via the command line. However, it is a special-purpose interface that
neither receives standard printk messages nor associates with
/dev/console.

Currently, the "preferred_dev_console" variable can point to a Braille
console entry in the "preferred_consoles[]" array. This occurs if an
entry was first created for a non-Braille console, but a later 'console='
parameter redefined it as a Braille console.

Since a Braille console will only ever be enabled as such, it should not
be tracked as the primary system console. Adjust the logic to ensure
"preferred_dev_console" continues to point to the previously designated
normal console instead.

Signed-off-by: Petr Mladek <pmladek@xxxxxxxx>
Assisted-by: gemini-1.5-pro
---
kernel/printk/console_register.h | 3 +++
kernel/printk/printk.c | 33 ++++++++++++++++++++++++++------
2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/kernel/printk/console_register.h b/kernel/printk/console_register.h
index 9ab3e1cc749b..64cf12fd6ea5 100644
--- a/kernel/printk/console_register.h
+++ b/kernel/printk/console_register.h
@@ -2,6 +2,8 @@
#ifndef _CONSOLE_REGISTER_H
#define _CONSOLE_REGISTER_H

+#include <linux/list.h>
+
struct preferred_console
{
char name[16]; /* Name of the driver */
@@ -12,6 +14,7 @@ struct preferred_console
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
char *brl_options; /* Options for braille driver */
#endif
+ struct list_head preferred_dev_node;
};

#endif
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 75d2a1085926..a2cc7bf3a62e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -366,7 +366,7 @@ static int console_locked;

static struct preferred_console preferred_consoles[MAX_PREFERRED_CONSOLES];

-static int preferred_dev_console = -1;
+static LIST_HEAD(preferred_dev_console);
static bool want_braille_console;
int console_set_on_cmdline;
EXPORT_SYMBOL(console_set_on_cmdline);
@@ -2567,9 +2567,16 @@ asmlinkage __visible void early_printk(const char *fmt, ...)
* 3. Allow to override @options via the command line. Last one wins
* except that the Braille variant is preferred.
*
+ * 4. Braille console is never associated with /dev/console.[**]
+ *
* [*] A valid @name and @idx will get assigned for a devname later when
* @devname matches during the device initialization, see
* match_devname_and_update_preferred_console().
+ *
+ * [**] Braille console is using the mechanism for registering consoles
+ * but it is very special. It is primarily used for user interaction
+ * with the system. It neither gets printk() messages nor is
+ * associated with /dev/console.
*/
static int add_or_update_preferred_console(unsigned int i,
const char *name, const short idx,
@@ -2645,10 +2652,24 @@ static int add_or_update_preferred_console(unsigned int i,
braille_set_options(pc, brl_options);
}

- if (brl_options)
+ if (is_new_entry)
+ INIT_LIST_HEAD(&pc->preferred_dev_node);
+
+ /*
+ * The last preferred console should get associated with /dev/console.
+ * Except for the Braille console which can't get associated with
+ * /dev/console.
+ */
+ if (brl_options) {
want_braille_console = true;
- else
- preferred_dev_console = i;
+ if (!list_empty(&pc->preferred_dev_node))
+ list_del_init(&pc->preferred_dev_node);
+ } else if (!is_braille_console_preferred(pc)) {
+ if (list_empty(&pc->preferred_dev_node))
+ list_add(&pc->preferred_dev_node, &preferred_dev_console);
+ else
+ list_move(&pc->preferred_dev_node, &preferred_dev_console);
+ }

if (user_specified) {
pc->user_specified = true;
@@ -4020,7 +4041,7 @@ static int __try_enable_preferred_console(struct console *newcon,
return err;
}
newcon->flags |= CON_ENABLED;
- if (i == preferred_dev_console)
+ if (list_is_first(&pc->preferred_dev_node, &preferred_dev_console))
newcon->flags |= CON_CONSDEV;
return 0;
}
@@ -4091,7 +4112,7 @@ static int try_enable_console(struct console *newcon)
* Note that a console with tty binding will have CON_CONSDEV
* flag set and will be first in the list.
*/
- if (preferred_dev_console < 0) {
+ if (list_empty(&preferred_dev_console)) {
if (hlist_empty(&console_list) || !console_first()->device ||
console_first()->flags & CON_BOOT) {
try_enable_default_console(newcon);
--
2.55.0