summaryrefslogtreecommitdiffstats
path: root/init/main.c
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2018-10-23 16:24:09 +0200
committerDominik Brodowski <linux@dominikbrodowski.net>2019-12-12 19:00:36 +0100
commit8243186f0cc7c57cf9d6a110cd7315c44e3e0be8 (patch)
tree16ca25ed6b291eb41de0d11b383fa7a263ad1121 /init/main.c
parentinit: unify opening /dev/console as stdin/stdout/stderr (diff)
downloadlinux-8243186f0cc7c57cf9d6a110cd7315c44e3e0be8.tar.xz
linux-8243186f0cc7c57cf9d6a110cd7315c44e3e0be8.zip
fs: remove ksys_dup()
ksys_dup() is used only at one place in the kernel, namely to duplicate fd 0 of /dev/console to stdout and stderr. The same functionality can be achieved by using functions already available within the kernel namespace. Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'init/main.c')
-rw-r--r--init/main.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/init/main.c b/init/main.c
index 2cd736059416..ec3a1463ac69 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 <asm/io.h>
#include <asm/bugs.h>
@@ -1157,13 +1158,26 @@ static int __ref kernel_init(void *unused)
void console_on_rootfs(void)
{
- /* Open the /dev/console as stdin, 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");
+ struct file *file;
+ unsigned int i;
+
+ /* Open /dev/console in kernelspace, this should never fail */
+ file = filp_open("/dev/console", O_RDWR, 0);
+ if (!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;
- /* create stdout/stderr */
- (void) ksys_dup(0);
- (void) ksys_dup(0);
+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)