All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dominik Brodowski <linux@dominikbrodowski.net>
To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	viro@zeniv.linux.org.uk
Cc: luto@kernel.org, mingo@kernel.org, akpm@linux-foundation.org,
	arnd@arndb.de
Subject: [PATCH v2 35/36] fs: add ksys_close() wrapper; remove in-kernel calls to sys_close()
Date: Thu, 15 Mar 2018 20:05:28 +0100	[thread overview]
Message-ID: <20180315190529.20943-36-linux@dominikbrodowski.net> (raw)
In-Reply-To: <20180315190529.20943-1-linux@dominikbrodowski.net>

Using the ksys_close() wrapper allows us to get rid of in-kernel calls
to the sys_close() syscall.

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().

Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
---
 fs/autofs4/dev-ioctl.c   |  2 +-
 fs/binfmt_misc.c         |  2 +-
 fs/file.c                |  1 +
 fs/open.c                |  1 -
 include/linux/syscalls.h | 12 ++++++++++++
 init/do_mounts.c         |  4 ++--
 init/do_mounts_initrd.c  |  2 +-
 init/do_mounts_md.c      |  8 ++++----
 init/do_mounts_rd.c      |  6 +++---
 init/initramfs.c         |  8 ++++----
 10 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index b7c816f39404..26f6b4f41ce6 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -310,7 +310,7 @@ static int autofs_dev_ioctl_closemount(struct file *fp,
 				       struct autofs_sb_info *sbi,
 				       struct autofs_dev_ioctl *param)
 {
-	return sys_close(param->ioctlfd);
+	return ksys_close(param->ioctlfd);
 }
 
 /*
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index a7c5a9861bef..a41b48f82a70 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -241,7 +241,7 @@ static int load_misc_binary(struct linux_binprm *bprm)
 	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;
diff --git a/fs/file.c b/fs/file.c
index d304004f0b65..7ffd6e9d103d 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -638,6 +638,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
 	spin_unlock(&files->file_lock);
 	return -EBADF;
 }
+EXPORT_SYMBOL(__close_fd); /* for ksys_close() */
 
 void do_close_on_exec(struct files_struct *files)
 {
diff --git a/fs/open.c b/fs/open.c
index b3f3b2cd9f19..710102fc262b 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1200,7 +1200,6 @@ SYSCALL_DEFINE1(close, unsigned int, fd)
 
 	return retval;
 }
-EXPORT_SYMBOL(sys_close);
 
 /*
  * This routine simulates a hangup on the tty, to arrange that users
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index fe9bac39f3c2..4ff0b01ab277 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1062,4 +1062,16 @@ static inline long ksys_lchown(const char __user *filename, uid_t user,
 			     AT_SYMLINK_NOFOLLOW);
 }
 
+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
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 89f18985fa90..a28dd42d1f84 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -492,7 +492,7 @@ void __init change_floppy(char *fmt, ...)
 	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);
@@ -503,7 +503,7 @@ void __init change_floppy(char *fmt, ...)
 		sys_read(fd, &c, 1);
 		termios.c_lflag |= ICANON;
 		sys_ioctl(fd, TCSETSF, (long)&termios);
-		sys_close(fd);
+		ksys_close(fd);
 	}
 }
 #endif
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index d30db6bbf014..50decd9999b7 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -111,7 +111,7 @@ static void __init handle_initrd(void)
 			error = fd;
 		} else {
 			error = sys_ioctl(fd, BLKFLSBUF, 0);
-			sys_close(fd);
+			ksys_close(fd);
 		}
 		printk(!error ? "okay\n" : "failed\n");
 	}
diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
index 3f733c760a8c..ebd4013d589e 100644
--- a/init/do_mounts_md.c
+++ b/init/do_mounts_md.c
@@ -191,7 +191,7 @@ static void __init md_setup_drive(void)
 			printk(KERN_WARNING
 			       "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
 			       minor);
-			sys_close(fd);
+			ksys_close(fd);
 			continue;
 		}
 
@@ -243,11 +243,11 @@ static void __init md_setup_drive(void)
 			 * 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);
 	}
 }
 
@@ -297,7 +297,7 @@ static void __init autodetect_raid(void)
 	fd = sys_open("/dev/md0", 0, 0);
 	if (fd >= 0) {
 		sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
-		sys_close(fd);
+		ksys_close(fd);
 	}
 }
 
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index 5b69056f610a..f1aa341862d3 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -257,7 +257,7 @@ int __init rd_load_image(char *from)
 		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;
 			}
@@ -283,9 +283,9 @@ int __init rd_load_image(char *from)
 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");
diff --git a/init/initramfs.c b/init/initramfs.c
index 0d3b001b0dc5..ce2bcad97cdf 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -373,7 +373,7 @@ static int __init do_copy(void)
 	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);
@@ -574,7 +574,7 @@ static void __init clean_rootfs(void)
 	buf = kzalloc(BUF_SIZE, GFP_KERNEL);
 	WARN_ON(!buf);
 	if (!buf) {
-		sys_close(fd);
+		ksys_close(fd);
 		return;
 	}
 
@@ -602,7 +602,7 @@ static void __init clean_rootfs(void)
 		num = sys_getdents64(fd, dirp, BUF_SIZE);
 	}
 
-	sys_close(fd);
+	ksys_close(fd);
 	kfree(buf);
 }
 #endif
@@ -639,7 +639,7 @@ static int __init populate_rootfs(void)
 				pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
 				       written, initrd_end - initrd_start);
 
-			sys_close(fd);
+			ksys_close(fd);
 			free_initrd();
 		}
 	done:
-- 
2.16.2

  parent reply	other threads:[~2018-03-15 19:06 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-15 19:04 [PATCH v2 00/36] remove in-kernel syscall invocations (part 1) Dominik Brodowski
2018-03-15 19:04 ` [PATCH v2 01/36] syscalls: define goal to not call sys_xyzzy() from within the kernel Dominik Brodowski
2018-03-15 19:04 ` [PATCH v2 02/36] kernel: use kernel_wait4() instead of sys_wait4() Dominik Brodowski
2018-03-16 16:58   ` Luis R. Rodriguez
2018-03-17 16:44     ` Dominik Brodowski
2018-03-15 19:04 ` [PATCH v2 03/36] mm: use do_futex() instead of sys_futex() in mm_release() Dominik Brodowski
2018-03-16 11:58   ` Thomas Gleixner
2018-03-16 18:43   ` Darren Hart
2018-03-16 19:03     ` Andy Lutomirski
2018-03-16 21:44       ` Darren Hart
2018-03-17 16:39         ` Dominik Brodowski
2018-03-15 19:04 ` [PATCH v2 04/36] kernel: add do_getpgid() helper; remove internal call to sys_getpgid() Dominik Brodowski
2018-03-15 19:04 ` [PATCH v2 05/36] fs: add do_readlinkat() helper; remove internal call to sys_readlinkat() Dominik Brodowski
2018-03-15 19:04 ` [PATCH v2 06/36] fs: add do_pipe2() helper; remove internal call to sys_pipe2() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 07/36] fs: add do_renameat2() helper; remove internal call to sys_renameat2() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 08/36] fs: add do_futimesat() helper; remove internal call to sys_futimesat() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 09/36] syscalls: add do_epoll_*() helpers; remove internal calls to sys_epoll_*() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 10/36] fs: add do_signalfd4() helper; remove internal calls to sys_signalfd4() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 11/36] fs: add do_eventfd() helper; remove internal call to sys_eventfd() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 12/36] kernel: open-code sys_rt_sigpending() in sys_sigpending() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 13/36] x86/ioport: add ksys_ioperm() helper; remove in-kernel calls to sys_ioperm() Dominik Brodowski
2018-03-16  8:43   ` Christoph Hellwig
2018-03-16 11:13     ` Dominik Brodowski
2018-03-16 12:00   ` Thomas Gleixner
2018-03-16 14:45     ` Dominik Brodowski
2018-03-16 14:47       ` Thomas Gleixner
2018-03-15 19:05 ` [PATCH v2 14/36] fs: add ksys_mount() helper; remove in-kernel calls to sys_mount() Dominik Brodowski
2018-03-15 20:11   ` Arnd Bergmann
2018-03-16  8:46     ` Christoph Hellwig
2018-03-16 16:58     ` Linus Torvalds
2018-03-17 16:52     ` Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 15/36] fs: add ksys_umount() helper; remove in-kernel call to sys_umount() Dominik Brodowski
2018-03-16  8:47   ` Christoph Hellwig
2018-03-17 16:58     ` Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 16/36] fs: add ksys_dup{,3}() helper; remove in-kernel calls to sys_dup{,3}() Dominik Brodowski
2018-03-16  8:48   ` Christoph Hellwig
2018-03-17 17:01     ` Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 17/36] fs: add ksys_chroot() helper; remove-in kernel calls to sys_chroot() Dominik Brodowski
2018-03-15 20:44   ` Arnd Bergmann
2018-03-16  8:49     ` Christoph Hellwig
2018-03-17 17:04     ` Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 18/36] fs: add ksys_write() helper; remove in-kernel calls to sys_write() Dominik Brodowski
2018-03-16  8:52   ` Christoph Hellwig
2018-03-17 17:06     ` Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 19/36] kernel: add ksys_unshare() helper; remove in-kernel calls to sys_unshare() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 20/36] mm: add ksys_fadvise64_64() helper; remove in-kernel call to sys_fadvise64_64() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 21/36] mm: add ksys_mmap_pgoff() helper; remove in-kernel calls to sys_mmap_pgoff() Dominik Brodowski
2018-03-15 20:54   ` Arnd Bergmann
2018-03-15 19:05 ` [PATCH v2 22/36] fs: add ksys_chdir() helper; remove in-kernel calls to sys_chdir() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 23/36] fs: add ksys_sync_file_range helper(); remove in-kernel calls to syscall Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 24/36] fs: add ksys_unlink() wrapper; remove in-kernel calls to sys_unlink() Dominik Brodowski
2018-03-15 20:21   ` Arnd Bergmann
2018-03-17 17:09     ` Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 25/36] hostfs: rename do_rmdir() to hostfs_do_rmdir() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 26/36] fs: add ksys_rmdir() wrapper; remove in-kernel calls to sys_rmdir() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 27/36] fs: add do_mkdirat() helper and ksys_mkdir() wrapper; remove in-kernel calls to syscall Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 28/36] fs: add do_symlinkat() helper and ksys_symlink() " Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 29/36] fs: add do_mknodat() helper and ksys_mknod() " Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 30/36] fs: add do_linkat() helper and ksys_link() " Dominik Brodowski
2018-03-15 20:30   ` Arnd Bergmann
2018-03-17 17:11     ` Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 31/36] fs: add ksys_fchmod() and do_fchmodat() helpers and ksys_chmod() " Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 32/36] fs: add do_faccessat() helper and ksys_access() " Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 33/36] fs: add ksys_ftruncate() wrapper; remove in-kernel calls to sys_ftruncate() Dominik Brodowski
2018-03-15 19:05 ` [PATCH v2 34/36] fs: add do_fchownat(), ksys_fchown() helpers and ksys_{,l}chown() wrappers Dominik Brodowski
2018-03-15 19:05 ` Dominik Brodowski [this message]
2018-03-15 19:05 ` [PATCH v2 36/36] fs: add ksys_open() wrapper; remove in-kernel calls to sys_open() Dominik Brodowski
2018-03-15 21:02 ` [PATCH v2 00/36] remove in-kernel syscall invocations (part 1) Arnd Bergmann
2018-03-16  0:38   ` Andy Lutomirski
2018-03-16  0:54     ` Linus Torvalds
2018-03-16  8:54       ` Christoph Hellwig
2018-03-16 14:20         ` Al Viro
2018-03-16 16:47           ` Linus Torvalds
2018-03-17 17:13   ` Dominik Brodowski
2018-03-16  9:01 ` Zhang, Ning A
2018-03-16 10:25   ` Dominik Brodowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180315190529.20943-36-linux@dominikbrodowski.net \
    --to=linux@dominikbrodowski.net \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.