Re: [PATCH v5 1/2] ttynull: Add an option to allow ttynull to be used as a console device
From: Andy Shevchenko
Date: Wed Feb 26 2025 - 14:23:16 EST
On Wed, Feb 26, 2025 at 3:39 PM Adam Simonelli <adamsimonelli@xxxxxxxxx> wrote:
> On Tuesday, February 25, 2025 11:19:04 AM EST Petr Mladek wrote:
...
> > My proposal is to call:
> >
> > #ifdef CONFIG_NULL_TTY_DEFAULT_CONSOLE
> > add_preferred_console("ttynull", 0, NULL);
> > #endif
> >
> > somewhere in the kernel code. The question is where.
> > I wonder if the following would work:
> >
>
> > #ifdef CONFIG_NULL_TTY_DEFAULT_CONSOLE
> > static int __init ttynull_default_console(void)
> > {
> > add_preferred_console("ttynull", 0, NULL);
> > return 0;
> > }
> > console_initcall(ttynull_register);
> > #endif
> >
> OK, actually in earlier revisions locally, I did actually have
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index dddb15f48d59..c1554a789de8 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -3712,6 +3712,11 @@ void __init console_init(void)
> initcall_t call;
> initcall_entry_t *ce;
>
> +#ifdef CONFIG_NULL_TTY_CONSOLE
> + if (!strstr(boot_command_line, "console="))
Just a side note: strstr() is fragile as theoretically "console=" can
be part of an argument unrelated to the console, like
foo="bar,baz,console=10,key=value". Although I haven't checked if this
is allowed by cmdline parser (lib/cmdline.c).
> + add_preferred_console("ttynull", 0, NULL);
> +#endif
> +
> /* Setup the default TTY line discipline. */
> n_tty_init();
>
>
>
> Which worked as far as I could tell, at least on x86. Not sure if that was the
> right place, and yeah, I was trying to better copy how CONFIG_VT_CONSOLE worked
> because I thought that was more correct.
--
With Best Regards,
Andy Shevchenko