Re: [PATCH v2 3/9] printk: Separate code for adding/updating preferred console metadata
From: Petr Mladek
Date: Fri May 29 2026 - 06:08:28 EST
On Fri 2026-05-15 12:36:58, John Ogness wrote:
> On 2026-05-15, John Ogness <john.ogness@xxxxxxxxxxxxx> wrote:
> >> + if (!pc->name[0]) {
> >> + strscpy(pc->name, name);
> >> + pc->index = idx;
> >
> > Here is the copied code. This block is about setting the name.
> >
> >> + } else if (strcmp(pc->name, name) != 0 || pc->index != idx) {
> >> + pr_err("Updating a preferred console with an invalid name or index: %s%d vs. %s%d\n",
> >> + pc->name, pc->index, name, idx);
> >> + return -EINVAL;
> >> + }
> >> + }
> >
> > I would put the index setting here as it is relevant regardless of how
> > the devname or name was updated.
> >
> > pc->index = idx;
>
> Ah, I guess you only wanted to update @index if it is a new entry
> (because otherwise it will already have the value of @idx).
Exactly ;-)
> If you want to keep the index setting in the devname and name blocks,
> maybe just adding a comment to clarify it is a new entry:
>
> if (!pc->devname[0]) {
> /* This is a new entry */
> strscpy(pc->devname, devname);
> pc->index = idx;
>
> ...
>
> if (!pc->name[0]) {
> /* This is a new entry */
> strscpy(pc->name, name);
> pc->index = idx;
I am going to add the comments in v3.
Best Regards,
Petr