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

From: John Ogness

Date: Thu Feb 19 2026 - 09:07:46 EST


On 2026-02-19, Petr Mladek <pmladek@xxxxxxxx> wrote:
>> On 2026-02-06, Petr Mladek <pmladek@xxxxxxxx> wrote:
>> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
>> > index 3f856a438e74..ee57c7ac9d02 100644
>> > --- a/kernel/printk/printk.c
>> > +++ b/kernel/printk/printk.c
>> > @@ -2491,18 +2491,82 @@ asmlinkage __visible void early_printk(const char *fmt, ...)
>> > }
>> > #endif
>> >
>> > -static void set_user_specified(struct preferred_console *pc, bool user_specified)
>> > +static int update_preferred_console(int i, const char *name, const short idx,
>>
>> Perhaps @i should be unsigned in order to guarantee no possibility of
>> negative array indexing.
>>
>> It would need to be defined that way in __add_preferred_console() as well.
>
> Makes sense. I'll do it in v2.

Note that it might cause some warnings due to comparing signed and
unsigned. It might be preferrable to check for non-negative rather than
making it unsigned.

> I am preparing v2 and added this:
>
> /** update_preferred_console - Update a given entry in the preferred_consoles[]
> * table.
> * @i: index of the entry in @preferred_consoles table which should get updated.
> * @name: The name of the preferred console driver.
> * @idx: Preferred console index, e.g. port number.
> * @devname: The name of the preferred physical device.
> * @options: Options used when setting up the console driver.
> * @brl_options: Options used when setting up the console driver
> * as a braille console.
> * @user_specified: True if preferred via the kernel command line.
> *
> * The function ensures that the given values are consistent. Also
> * it updates some global variables which are used to make the right
> * decisions in register_console().
> *
> * Rules:
> *
> * 1. Either @name and valid @idx OR @devname and @idx=-1 are allowed.
> * Note that a valid @name and @idx will get assigned later when
> * @devname matches during the device initialization.
> * 2. Specify @brl_options if the console should be enabled as
> * a Braille console [*]
> * 3. Only matching entries can be updated.
> * 4. @options passed via the command line are used when the same
> * console is is preferred also by some platform-specific code.
> *
> * [*] Braille console is using the mechanism for registering consoles
> * but it is very special. It is primary used for an user interaction
> * with the system.

Grammar fixup:

It is primarily used for user interaction with the system.
> * with the system. It neither gets printk() messages nor is
> * associated with /dev/cosnole.

/dev/console spelled wrong.

> */

Otherwise, LGTM.

I can provide reviewed-by tags once I look over v2.

John