Skip to content

Commit 8243186

Browse files
author
Dominik Brodowski
committed
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 <[email protected]>
1 parent b49a733 commit 8243186

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

fs/file.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd)
960960
return ksys_dup3(oldfd, newfd, 0);
961961
}
962962

963-
int ksys_dup(unsigned int fildes)
963+
SYSCALL_DEFINE1(dup, unsigned int, fildes)
964964
{
965965
int ret = -EBADF;
966966
struct file *file = fget_raw(fildes);
@@ -975,11 +975,6 @@ int ksys_dup(unsigned int fildes)
975975
return ret;
976976
}
977977

978-
SYSCALL_DEFINE1(dup, unsigned int, fildes)
979-
{
980-
return ksys_dup(fildes);
981-
}
982-
983978
int f_dupfd(unsigned int from, struct file *file, unsigned flags)
984979
{
985980
int err;

include/linux/syscalls.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,6 @@ asmlinkage long sys_ni_syscall(void);
12321232
*/
12331233

12341234
int ksys_umount(char __user *name, int flags);
1235-
int ksys_dup(unsigned int fildes);
12361235
int ksys_chroot(const char __user *filename);
12371236
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
12381237
int ksys_chdir(const char __user *filename);

init/main.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
#include <linux/rodata_test.h>
9494
#include <linux/jump_label.h>
9595
#include <linux/mem_encrypt.h>
96+
#include <linux/file.h>
9697

9798
#include <asm/io.h>
9899
#include <asm/bugs.h>
@@ -1157,13 +1158,26 @@ static int __ref kernel_init(void *unused)
11571158

11581159
void console_on_rootfs(void)
11591160
{
1160-
/* Open the /dev/console as stdin, this should never fail */
1161-
if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
1162-
pr_err("Warning: unable to open an initial console.\n");
1161+
struct file *file;
1162+
unsigned int i;
1163+
1164+
/* Open /dev/console in kernelspace, this should never fail */
1165+
file = filp_open("/dev/console", O_RDWR, 0);
1166+
if (!file)
1167+
goto err_out;
1168+
1169+
/* create stdin/stdout/stderr, this should never fail */
1170+
for (i = 0; i < 3; i++) {
1171+
if (f_dupfd(i, file, 0) != i)
1172+
goto err_out;
1173+
}
1174+
1175+
return;
11631176

1164-
/* create stdout/stderr */
1165-
(void) ksys_dup(0);
1166-
(void) ksys_dup(0);
1177+
err_out:
1178+
/* no panic -- this might not be fatal */
1179+
pr_err("Warning: unable to open an initial console.\n");
1180+
return;
11671181
}
11681182

11691183
static noinline void __init kernel_init_freeable(void)

0 commit comments

Comments
 (0)