Re: [PATCH v5 07/16] printk: Ensure consistent name and devname when updating preferred console
From: Chris Down
Date: Thu Oct 29 2026 - 03:10:30 EST
Petr Mladek writes:
>- strscpy(pc->name, name);
>- pc->index = idx;
>+ if (!pc->name[0]) {
>+ is_new_entry = true;
>+ strscpy(pc->name, name);
>+ pc->index = idx;
console_setup() can hand us an empty name or devname:
console=,115200 -> name "", idx 0, options "115200"
console=,foo:bar -> devname "", idx -1, options "foo:bar"
For the devname case, __add_preferred_console() matches the first name-only
entry (`strcmp(pc->devname, "") == 0`), e.g. the SPCR "pl011"/0 entry, and this
hunk now treats it as new.
Then index becomes -1 and options become "foo:bar", so the SPCR console never
matches again. Before the series that command line only moved
preferred_console.
For the `!pc->name[0]` branch below the slot keeps looking unused, which turns
into list corruption with 14/16 (I'll put some details over there instead of
duplicating it here).
Rejecting empty strings up front, after the `WARN_ON(!name && !devname)`, fixes
both:
if ((name && !name[0]) || (devname && !devname[0])) {
pr_err("Adding a preferred console with an empty name\n");
return -EINVAL;
}