diff mbox series

[14/19] finit_module(): convert to CLASS(fd, ...)

Message ID 20240607015957.2372428-14-viro@zeniv.linux.org.uk (mailing list archive)
State New
Headers show
Series [01/19] powerpc: fix a file leak in kvm_vcpu_ioctl_enable_cap() | expand

Commit Message

Al Viro June 7, 2024, 1:59 a.m. UTC
Slightly unidiomatic emptiness check; just lift it out of idempotent_init_module()
and into finit_module(2) and that's it.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 kernel/module/main.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/kernel/module/main.c b/kernel/module/main.c
index 98fda13fdca7..f2f045b3740d 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -3177,7 +3177,7 @@  static int idempotent_init_module(struct file *f, const char __user * uargs, int
 {
 	struct idempotent idem;
 
-	if (!f || !(f->f_mode & FMODE_READ))
+	if (!(f->f_mode & FMODE_READ))
 		return -EBADF;
 
 	/* See if somebody else is doing the operation? */
@@ -3193,10 +3193,7 @@  static int idempotent_init_module(struct file *f, const char __user * uargs, int
 
 SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
 {
-	int err;
-	struct fd f;
-
-	err = may_init_module();
+	int err = may_init_module();
 	if (err)
 		return err;
 
@@ -3207,10 +3204,10 @@  SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
 		      |MODULE_INIT_COMPRESSED_FILE))
 		return -EINVAL;
 
-	f = fdget(fd);
-	err = idempotent_init_module(fd_file(f), uargs, flags);
-	fdput(f);
-	return err;
+	CLASS(fd, f)(fd);
+	if (fd_empty(f))
+		return -EBADF;
+	return idempotent_init_module(fd_file(f), uargs, flags);
 }
 
 /* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */