Re: [PATCH v5 07/16] printk: Ensure consistent name and devname when updating preferred console
From: Petr Mladek
Date: Tue Nov 03 2026 - 12:56:42 EST
On Thu 2026-10-29 15:09:52, Chris Down wrote:
> 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).
Great catch! I think that even the original code did not expect that
anyone could pass "" as either @name or @devname.
> 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;
> }
I like this. I am going to add this as a separate patch.
As mentioned above, I think that it was not handled before...
I have the following as the 5th patch: