Using the ksys_close() wrapper allows us to get rid of in-kernel calls
to the sys_close() syscall. The ksys_ prefix denotes that this function
is meant as a drop-in replacement for the syscall. In particular, it
uses the same calling convention as sys_close(), with one subtle
difference:
The few places which checked the return value did not care about the return
value re-writing in sys_close(), so simply use a wrapper around
__close_fd().
This patch is part of a series which removes in-kernel calls to syscalls.
On this basis, the syscall entry path can be streamlined. For details, see
http://lkml.kernel.org/r/
20180325162527.GA17492@light.dominikbrodowski.net
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
struct autofs_sb_info *sbi,
struct autofs_dev_ioctl *param)
{
- return sys_close(param->ioctlfd);
+ return ksys_close(param->ioctlfd);
}
/*
return retval;
error:
if (fd_binary > 0)
- sys_close(fd_binary);
+ ksys_close(fd_binary);
bprm->interp_flags = 0;
bprm->interp_data = 0;
goto ret;
spin_unlock(&files->file_lock);
return -EBADF;
}
+EXPORT_SYMBOL(__close_fd); /* for ksys_close() */
void do_close_on_exec(struct files_struct *files)
{
return retval;
}
-EXPORT_SYMBOL(sys_close);
/*
* This routine simulates a hangup on the tty, to arrange that users
return do_sys_ftruncate(fd, length, 1);
}
+extern int __close_fd(struct files_struct *files, unsigned int fd);
+
+/*
+ * In contrast to sys_close(), this stub does not check whether the syscall
+ * should or should not be restarted, but returns the raw error codes from
+ * __close_fd().
+ */
+static inline int ksys_close(unsigned int fd)
+{
+ return __close_fd(current->files, fd);
+}
+
#endif
fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
if (fd >= 0) {
sys_ioctl(fd, FDEJECT, 0);
- sys_close(fd);
+ ksys_close(fd);
}
printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
fd = sys_open("/dev/console", O_RDWR, 0);
sys_read(fd, &c, 1);
termios.c_lflag |= ICANON;
sys_ioctl(fd, TCSETSF, (long)&termios);
- sys_close(fd);
+ ksys_close(fd);
}
}
#endif
error = fd;
} else {
error = sys_ioctl(fd, BLKFLSBUF, 0);
- sys_close(fd);
+ ksys_close(fd);
}
printk(!error ? "okay\n" : "failed\n");
}
printk(KERN_WARNING
"md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
minor);
- sys_close(fd);
+ ksys_close(fd);
continue;
}
* boot a kernel with devfs compiled in from partitioned md
* array without it
*/
- sys_close(fd);
+ ksys_close(fd);
fd = sys_open(name, 0, 0);
sys_ioctl(fd, BLKRRPART, 0);
}
- sys_close(fd);
+ ksys_close(fd);
}
}
fd = sys_open("/dev/md0", 0, 0);
if (fd >= 0) {
sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
- sys_close(fd);
+ ksys_close(fd);
}
}
if (i && (i % devblocks == 0)) {
printk("done disk #%d.\n", disk++);
rotate = 0;
- if (sys_close(in_fd)) {
+ if (ksys_close(in_fd)) {
printk("Error closing the disk.\n");
goto noclose_input;
}
successful_load:
res = 1;
done:
- sys_close(in_fd);
+ ksys_close(in_fd);
noclose_input:
- sys_close(out_fd);
+ ksys_close(out_fd);
out:
kfree(buf);
ksys_unlink("/dev/ram");
if (byte_count >= body_len) {
if (xwrite(wfd, victim, body_len) != body_len)
error("write error");
- sys_close(wfd);
+ ksys_close(wfd);
do_utime(vcollected, mtime);
kfree(vcollected);
eat(body_len);
buf = kzalloc(BUF_SIZE, GFP_KERNEL);
WARN_ON(!buf);
if (!buf) {
- sys_close(fd);
+ ksys_close(fd);
return;
}
num = sys_getdents64(fd, dirp, BUF_SIZE);
}
- sys_close(fd);
+ ksys_close(fd);
kfree(buf);
}
#endif
pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
written, initrd_end - initrd_start);
- sys_close(fd);
+ ksys_close(fd);
free_initrd();
}
done: