Re: [PATCH v2 3/9] printk: Separate code for adding/updating preferred console metadata

From: John Ogness

Date: Fri May 15 2026 - 07:09:57 EST


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).

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;

John