Skip to content

Commit f073531

Browse files
Christoph HellwigAl Viro
authored andcommitted
init: add an init_dup helper
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 <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 235e579 commit f073531

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

fs/init.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/namei.h>
99
#include <linux/fs.h>
1010
#include <linux/fs_struct.h>
11+
#include <linux/file.h>
1112
#include <linux/init_syscalls.h>
1213
#include <linux/security.h>
1314
#include "internal.h"
@@ -251,3 +252,14 @@ int __init init_utimes(char *filename, struct timespec64 *ts)
251252
path_put(&path);
252253
return error;
253254
}
255+
256+
int __init init_dup(struct file *file)
257+
{
258+
int fd;
259+
260+
fd = get_unused_fd_flags(0);
261+
if (fd < 0)
262+
return fd;
263+
fd_install(fd, get_file(file));
264+
return 0;
265+
}

include/linux/init_syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ int __init init_unlink(const char *pathname);
1616
int __init init_mkdir(const char *pathname, umode_t mode);
1717
int __init init_rmdir(const char *pathname);
1818
int __init init_utimes(char *filename, struct timespec64 *ts);
19+
int __init init_dup(struct file *file);

init/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,10 +1467,10 @@ void __init console_on_rootfs(void)
14671467
pr_err("Warning: unable to open an initial console.\n");
14681468
return;
14691469
}
1470-
get_file_rcu_many(file, 2);
1471-
fd_install(get_unused_fd_flags(0), file);
1472-
fd_install(get_unused_fd_flags(0), file);
1473-
fd_install(get_unused_fd_flags(0), file);
1470+
init_dup(file);
1471+
init_dup(file);
1472+
init_dup(file);
1473+
fput(file);
14741474
}
14751475

14761476
static noinline void __init kernel_init_freeable(void)

0 commit comments

Comments
 (0)