summaryrefslogtreecommitdiff
path: root/init/main.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2019-12-30 10:10:51 +0300
committerIngo Molnar <mingo@kernel.org>2019-12-30 10:10:51 +0300
commit28336be568bb473d16ba80db0801276fb4f1bbe5 (patch)
treecf2d7a56e6c3ea08139d8d9a5a58b296bd172136 /init/main.c
parent5cbaefe9743bf14c9d3106db0cc19f8cb0a3ca22 (diff)
parentfd6988496e79a6a4bdb514a4655d2920209eb85d (diff)
downloadlinux-28336be568bb473d16ba80db0801276fb4f1bbe5.tar.xz
Merge tag 'v5.5-rc4' into locking/kcsan, to resolve conflicts
Conflicts: init/main.c lib/Kconfig.debug Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'init/main.c')
-rw-r--r--init/main.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/init/main.c b/init/main.c
index 4d814de017ee..919f65faeb7e 100644
--- a/init/main.c
+++ b/init/main.c
@@ -93,6 +93,7 @@
#include <linux/rodata_test.h>
#include <linux/jump_label.h>
#include <linux/mem_encrypt.h>
+#include <linux/file.h>
#include <linux/kcsan.h>
#include <asm/io.h>
@@ -1157,6 +1158,30 @@ static int __ref kernel_init(void *unused)
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
+void console_on_rootfs(void)
+{
+ struct file *file;
+ unsigned int i;
+
+ /* Open /dev/console in kernelspace, this should never fail */
+ file = filp_open("/dev/console", O_RDWR, 0);
+ if (IS_ERR(file))
+ goto err_out;
+
+ /* create stdin/stdout/stderr, this should never fail */
+ for (i = 0; i < 3; i++) {
+ if (f_dupfd(i, file, 0) != i)
+ goto err_out;
+ }
+
+ return;
+
+err_out:
+ /* no panic -- this might not be fatal */
+ pr_err("Warning: unable to open an initial console.\n");
+ return;
+}
+
static noinline void __init kernel_init_freeable(void)
{
/*
@@ -1192,12 +1217,8 @@ static noinline void __init kernel_init_freeable(void)
do_basic_setup();
- /* Open the /dev/console on the rootfs, this should never fail */
- if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
- pr_err("Warning: unable to open an initial console.\n");
+ console_on_rootfs();
- (void) ksys_dup(0);
- (void) ksys_dup(0);
/*
* check if there is an early userspace init. If yes, let it do all
* the work