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

From: Petr Mladek

Date: Fri Nov 06 2026 - 12:23:56 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>
Acked-by: Chris Down <chris@xxxxxxxxxxxxxx>
---
kernel/printk/console_register.h | 3 +++
kernel/printk/printk.c | 31 ++++++++++++++++++++++++-------
2 files changed, 27 insertions(+), 7 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 2bcf82b2c4e3..5ec34dc2d168 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -365,7 +365,7 @@ static int console_locked;
#define MAX_PREFERRED_CONSOLES 8
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;
/* Set when there is at least one console preferred via the command line. */
int console_set_on_cmdline;
@@ -2567,9 +2567,16 @@ asmlinkage __visible void early_printk(const char *fmt, ...)
*
* 3. Only matching entries can be updated.
*
+ * 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,
@@ -2649,10 +2656,20 @@ 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;
+ list_del_init(&pc->preferred_dev_node);
+ } else if (!is_braille_console_preferred(pc)) {
+ list_move(&pc->preferred_dev_node, &preferred_dev_console);
+ }

if (user_specified) {
/*
@@ -4035,7 +4052,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;
}
@@ -4079,7 +4096,7 @@ static int try_enable_console(struct console *newcon)
/*
* First, try to enable the console driver as a Braille console.
* It would have metadata in the preferred_consoles[] array.
- * But it won't be counted as preferred_dev_console because
+ * But it won't be listed as preferred_dev_console because
* it does not get printk() messages and is not associated
* with /dev/console.
*
@@ -4106,7 +4123,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.56.0