Re: [PATCH v5 14/16] printk: Do not set Braille console as preferred_console
From: Petr Mladek
Date: Fri Nov 06 2026 - 09:23:31 EST
On Thu 2026-10-29 15:19:59, Chris Down wrote:
> Petr Mladek writes:
> >- if (brl_options)
> >+ if (is_new_entry)
> >+ INIT_LIST_HEAD(&pc->preferred_dev_node);
>
> is_new_entry is derived from pc->name[0]/pc->devname[0] being empty, and
> console_setup() can store an empty name:
>
> console=,115200 console=tty1
>
> The first one creates an entry with name "" (and links it). The second one
> stops the lookup loop at the same slot, sees it as new again, and
> re-initialises a node which is still linked, followed by list_add(). With
> DEBUG_LIST + BUG_ON_DATA_CORRUPTION:
>
> list_add corruption. next->prev should be prev (ffffb010209fc0c0), but was ffffb01023cd1fa0. (next=ffffb01023cd1fa0).
> kernel BUG at lib/list_debug.c:29!
> Call trace:
> __list_add_valid_or_report+0xbc/0x1c0 (P)
> add_or_update_preferred_console+0x6fc/0x9c0
> __add_preferred_console+0x11c/0x160
> console_setup+0x2e4/0x348
> obsolete_checksetup+0x148/0x190
> unknown_bootoption+0x150/0x328
> parse_one+0x108/0x480
> parse_args+0x158/0x3d0
> start_kernel+0x134/0x488
>
> "console=,foo:bar" does the same on the first console= when SPCR added an
> entry, since it matches the SPCR slot via the empty devname (see 7/16).
>
> Rejecting empty name/devname in add_or_update_preferred_console() (see my
> comment on 7/16) should fix that.
Yup, it will be fixed in v6 this way.
> >- 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);
>
> list_del_init() and list_move() are both fine on an initialised self-linked
> node (list_move() passes the DEBUG_LIST checks in __list_del_entry_valid()), so
> the list_empty() checks can go.
I was lazy to check this and wanted to stay on the safe side ;-)
OK, I am going to do the following changes for v6:
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2666,13 +2666,9 @@ static int add_or_update_preferred_console(unsigned int i,
*/
if (brl_options) {
want_braille_console = true;
- if (!list_empty(&pc->preferred_dev_node))
- list_del_init(&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);
+ list_move(&pc->preferred_dev_node, &preferred_dev_console);
}
if (user_specified) {
> With these fixed:
>
> Acked-by: Chris Down <chris@xxxxxxxxxxxxxx>
Thanks.
Best Regards,
Petr