aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/ttynull.c
diff options
context:
space:
mode:
authorPetr Mladek <pmladek@suse.com>2020-11-11 14:54:49 +0100
committerPetr Mladek <pmladek@suse.com>2020-11-20 12:23:50 +0100
commit757055ae8dedf5333af17b3b5b4b70ba9bc9da4e (patch)
treef7cd4581dd54753277acbe1822277ed98743ed55 /drivers/tty/ttynull.c
parentMerge tag 'printk-for-5.10-fixup' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux (diff)
downloadlinux-dev-757055ae8dedf5333af17b3b5b4b70ba9bc9da4e.tar.xz
linux-dev-757055ae8dedf5333af17b3b5b4b70ba9bc9da4e.zip
init/console: Use ttynull as a fallback when there is no console
stdin, stdout, and stderr standard I/O stream are created for the init process. They are not available when there is no console registered for /dev/console. It might lead to a crash when the init process tries to use them, see the commit 48021f98130880dd742 ("printk: handle blank console arguments passed in."). Normally, ttySX and ttyX consoles are used as a fallback when no consoles are defined via the command line, device tree, or SPCR. But there will be no console registered when an invalid console name is configured or when the configured consoles do not exist on the system. Users even try to avoid the console intentionally, for example, by using console="" or console=null. It is used on production systems where the serial port or terminal are not visible to users. Pushing messages to these consoles would just unnecessary slowdown the system. Make sure that stdin, stdout, stderr, and /dev/console are always available by a fallback to the existing ttynull driver. It has been implemented for exactly this purpose but it was used only when explicitly configured. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Tested-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20201111135450.11214-2-pmladek@suse.com
Diffstat (limited to 'drivers/tty/ttynull.c')
-rw-r--r--drivers/tty/ttynull.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/tty/ttynull.c b/drivers/tty/ttynull.c
index 17f05b7eb6d3..eced70ec54e1 100644
--- a/drivers/tty/ttynull.c
+++ b/drivers/tty/ttynull.c
@@ -2,6 +2,13 @@
/*
* Copyright (C) 2019 Axis Communications AB
*
+ * The console is useful for userspace applications which expect a console
+ * device to work without modifications even when no console is available
+ * or desired.
+ *
+ * In order to use this driver, you should redirect the console to this
+ * TTY, or boot the kernel with console=ttynull.
+ *
* Based on ttyprintk.c:
* Copyright (C) 2010 Samo Pogacnik
*/
@@ -59,6 +66,17 @@ static struct console ttynull_console = {
.device = ttynull_device,
};
+void __init register_ttynull_console(void)
+{
+ if (!ttynull_driver)
+ return;
+
+ if (add_preferred_console(ttynull_console.name, 0, NULL))
+ return;
+
+ register_console(&ttynull_console);
+}
+
static int __init ttynull_init(void)
{
struct tty_driver *driver;