On Wed 2025-02-26 08:39:23, Adam Simonelli wrote: > On Tuesday, February 25, 2025 11:19:04 AM EST Petr Mladek wrote: > > On Mon 2025-02-24 07:39:14, adamsimonelli@xxxxxxxxx wrote: > > > From: Adam Simonelli <adamsimonelli@xxxxxxxxx> > > > > > > The new config option, CONFIG_NULL_TTY_CONSOLE will allow ttynull to be > > > initialized by console_initcall() and selected as a possible console > > > device. > > > > > > diff --git a/drivers/tty/ttynull.c b/drivers/tty/ttynull.c > > > index 6b2f7208b564..ec3dd3fd41c0 100644 > > > --- a/drivers/tty/ttynull.c > > > +++ b/drivers/tty/ttynull.c > > > @@ -57,6 +57,13 @@ static struct tty_driver *ttynull_device(struct console *c, int *index) > > > static struct console ttynull_console = { > > > .name = "ttynull", > > > .device = ttynull_device, > > > + > > > + /* > > > + * Match the index and flags from other boot consoles when CONFIG_NULL_TTY_CONSOLE is > > > + * enabled, otherwise, use the default values for the index and flags. > > > + */ > > > + .index = IS_ENABLED(CONFIG_NULL_TTY_CONSOLE) ? -1 : 0, > > > > This should not be needed. "con->index" is always initialized to "0" > > for the default console, see: > > > OK, I had this in an #ifdef before, it was the cleanest way to set it to -1 > that I could think of, other than the ifdef... If I still need this, I will try > to think of something else to set it to -1 when the option is enabled Ah, I was not clear enough. It should be perfectly fine to always statically initialize the value to -1. We should not need any #ifdef or IS_ENABLED. I mean to do: static struct console ttynull_console = { .name = "ttynull", .device = ttynull_device, .index = -1, }; We might even do this in a separate patch. IMHO, it should have been done this way since the beginning. > > static void try_enable_default_console(struct console *newcon) > > { > > if (newcon->index < 0) > > newcon->index = 0; > > [...] > > } > > > > > + .flags = IS_ENABLED(CONFIG_NULL_TTY_CONSOLE) ? CON_PRINTBUFFER : 0, > > > > This does not make much sense to me. > > > > CON_PRINTBUFFER prevents duplicated output when the same device has > > already been registered as a boot console. But ttynull does not have > > a boot console variant. Also it is a "null" device. It never prints > > anything. The output could never be duplicated by definition. > > > OK, I was duplicating what I saw in other consoles. I can try to remove it Again, I was not clear enough. My primary concern was that it did not make much sense to use the IS_ENABLED() check and initialize the value different way. Anyway, I would omit the flag. It is a NULL device. It does not matter whether it prints existing (old) messages during registration or not. > > > }; > > > > > My proposal is to call: > > > > #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=")) > + add_preferred_console("ttynull", 0, NULL); Good point! We should call add_preferred_console() only when the is no console= command line parameter. Otherwise, it could not get overridden by the command line. We could check "console_set_on_cmdline", similar to xenfb_make_preferred_console(). > +#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, I would prefer to keep it in drivers/tty/ttynull.c when possible. The following might do the trick: #ifdef CONFIG_NULL_TTY_DEFAULT_CONSOLE static int __init ttynull_default_console(void) { if (!console_set_on_cmdline) add_preferred_console("ttynull", 0, NULL); return 0; } console_initcall(ttynull_register); #endif Best Regards, Petr