Re: [PATCH v5 13/16] printk: Try to register each console as Braille first

From: Petr Mladek

Date: Fri Nov 06 2026 - 06:45:01 EST


On Tue 2026-09-29 14:05:43, Petr Mladek wrote:
> Braille consoles are unique: they can only be enabled via the command
> line and use the preferred console framework for initialization, yet
> they are never added to the console_list or associated with
> /dev/console. Because of this, the preferred_console variable remains
> unset when only a Braille console is requested.
>
> Currently, try_enable_preferred_console() must be called even when
> "preferred_dev_console" variable is not set, just to catch these "hidden"
> Braille requests.
>
> Refactor the logic by adding a parameter to try_enable_preferred_console()
> to explicitly handle Braille vs. non-Braille cases. It will eventually
> allow to skip try_enable_preferred_console() when there are no preferred
> consoles. This improves code robustness by ensuring the console
> setup is explicit and only performed once.
>
> Note that _braille_register_console() is skipped when the given console
> driver has a match() callback and it succeeded. It means that it took
> over an early console and can't be used as a Braille console.
>
> As a result try_enable_braille_console() might return success even
> when it did not enabled the console in the Braille mode. It is
> the reason why register_console() has to explicitly check whether
> CON_BRL flag was really set and could skip the further steps.
>
> The refactoring even fixes two subtle bugs:
>
> 1. When only the Braille console is defined on the command line,
> the original code might attempt to enable the same console twice—once
> as a default and once as a Braille console. This results in calling
> the setup() callback twice and incorrectly setting the CON_CONSDEV flag.
>
> 2. When the same console is defined on the command line using devname
> and then as Braille console, for example:
>
> console=00:00:0.0,115200 console=brl,ttyS0,115200
>
> It would have two separate entries in preferred_consoles[] array.
>
> The 2nd (Braille) entry would be used when univ8250_console_init()
> tries to register the generic "ttyS" console driver. Note that
> the 1st entry still does not have defined the "name" entry at
> this stage.
>
> The 1st non-Braille entry would be used later when serial8250_init()
> registers all found devices, assigns "tty0" for the given "00:00:0.0"
> devname and tries to register the same struct console once again.
>
> The original code would call newcon->setup() twice in this scenario.
> It won't add the console into console_list only because the later
> check in register_console() would detect CON_BRL flag set from
> the 1st registration and return early.
>
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -3995,7 +4012,7 @@ static int try_enable_preferred_console(struct console *newcon,
> if (newcon->index < 0)
> newcon->index = pc->index;
>
> - if (is_braille_console_preferred(pc))
> + if (try_only_braille)
> return _braille_register_console(newcon, pc);
>
> err = console_call_setup(newcon, pc->options);

>From Sashiko AI:

| Does returning 0 here for a Braille match cause the console to lose its
| preferred status?
|
| When newcon->match() succeeds, the loop falls through to:
|
| newcon->flags |= CON_ENABLED;
| if (i == preferred_dev_console)
| newcon->flags |= CON_CONSDEV;
| return 0;
|
| When returning 0 here after a successful newcon->match() during the
| try_only_braille phase, CON_CONSDEV is not set because preferred_dev_console
| is never assigned to a Braille entry.

This works as expected. The CON_CONSDEV flag is set here only when
the related preferred_consoles[i] entry was the latest added/updated
entry for a non-Braille console.

Note that there are more situations when the `preferred_dev_console`
is not registered, for example, when there is a typo, or when
the related HW is not available.

For this situation, the CON_CONSDEV flag is always assigned to the
1st registered console driver, see the commit 33225d7b0ac990
("printk: Correctly set CON_CONSDEV even when preferred console
was not registered").

[ ... ]

> @@ -4033,6 +4061,24 @@ static int try_enable_console(struct console *newcon)
> {
> int err;
>
> + /*
> + * 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_console because
> + * it does not get printk() messages and is not associated
> + * with /dev/console.
> + *
> + * Note that it might succeed also when the driver has a match()
> + * callback and it took over a boot console. In this case,
> + * the driver will continue working as a classic non-Braille
> + * console.
> + */
> + if (want_braille_console) {
> + err = try_enable_braille_console(newcon);
> + if (err != -ENOENT)
> + return err;
> + }

Sashiko AI wrote:

| If the user specified both a regular console and a Braille console
| (e.g. console=ttyS0 console=brl,uart,...), does this early return preempt
| the regular console entry from being evaluated?
|
| If a driver matches the Braille entry and returns 0 without setting
| CON_CONSDEV, returning early here means the regular preferred console entries
| are skipped. This seems to break /dev/console routing, as the expected
| primary console never receives CON_CONSDEV.

The problem with CON_CONSDEV is basically the same as above.

But there is another interesting question whether the console driver
can be used as a classic printk console even it could not get enabled
as a Braille console. I mean whether, for example,
try_enable_default_console(newcon) would fail when
try_enable_braille_console(newcon) failed.

I could imagine that the driver might be usable and only the
VT integration failed. But the VT integration never fails,
see braille_register_console().

Also I think that we do not want to use this driver as a normal
console when it was configured to be used by the Braille console.

Best Regards,
Petr