]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
init: add an init_dup helper
authorChristoph Hellwig <hch@lst.de>
Tue, 28 Jul 2020 15:49:47 +0000 (17:49 +0200)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 5 Aug 2020 01:02:38 +0000 (21:02 -0400)
Add a simple helper to grab a reference to a file and install it at
the next available fd, and switch the early init code over to it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/init.c
include/linux/init_syscalls.h
init/main.c

index db5c48a85644fa19eada4788cf7d7faa72e08f4f..e9c320a48cf157dd5ad1ffe5f9d40f20bd75656e 100644 (file)
--- a/fs/init.c
+++ b/fs/init.c
@@ -8,6 +8,7 @@
 #include <linux/namei.h>
 #include <linux/fs.h>
 #include <linux/fs_struct.h>
+#include <linux/file.h>
 #include <linux/init_syscalls.h>
 #include <linux/security.h>
 #include "internal.h"
@@ -251,3 +252,14 @@ int __init init_utimes(char *filename, struct timespec64 *ts)
        path_put(&path);
        return error;
 }
+
+int __init init_dup(struct file *file)
+{
+       int fd;
+
+       fd = get_unused_fd_flags(0);
+       if (fd < 0)
+               return fd;
+       fd_install(fd, get_file(file));
+       return 0;
+}
index 3654b525ac0b173a9ad3adccbe9d854f44395c3c..92045d18cbfc994a9524733cd1f5febdd3019f92 100644 (file)
@@ -16,3 +16,4 @@ int __init init_unlink(const char *pathname);
 int __init init_mkdir(const char *pathname, umode_t mode);
 int __init init_rmdir(const char *pathname);
 int __init init_utimes(char *filename, struct timespec64 *ts);
+int __init init_dup(struct file *file);
index 1c710d3e1d461a6b58d47179e418d940e79a7c9c..9dae9c4f806bb97bd511d4dd1cab3a6a2c0cc56c 100644 (file)
@@ -1467,10 +1467,10 @@ void __init console_on_rootfs(void)
                pr_err("Warning: unable to open an initial console.\n");
                return;
        }
-       get_file_rcu_many(file, 2);
-       fd_install(get_unused_fd_flags(0), file);
-       fd_install(get_unused_fd_flags(0), file);
-       fd_install(get_unused_fd_flags(0), file);
+       init_dup(file);
+       init_dup(file);
+       init_dup(file);
+       fput(file);
 }
 
 static noinline void __init kernel_init_freeable(void)