]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
make use of anon_inode_getfile_fmode()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 18 Jan 2025 01:44:34 +0000 (01:44 +0000)
committerChristian Brauner <brauner@kernel.org>
Fri, 21 Feb 2025 09:25:31 +0000 (10:25 +0100)
["fallen through the cracks" misc stuff]

A bunch of anon_inode_getfile() callers follow it with adjusting
->f_mode; we have a helper doing that now, so let's make use
of it.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Link: https://lore.kernel.org/r/20250118014434.GT1977892@ZenIV
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
arch/powerpc/platforms/pseries/papr-vpd.c
drivers/vfio/group.c
fs/cachefiles/ondemand.c
fs/eventfd.c
fs/signalfd.c
fs/timerfd.c
virt/kvm/kvm_main.c

index 1574176e3ffc79923f35133920242541cf4dbcca..c86950d7105aa8468dd7364d5aab4a430519ab51 100644 (file)
@@ -482,14 +482,13 @@ static long papr_vpd_create_handle(struct papr_location_code __user *ulc)
                goto free_blob;
        }
 
-       file = anon_inode_getfile("[papr-vpd]", &papr_vpd_handle_ops,
-                                 (void *)blob, O_RDONLY);
+       file = anon_inode_getfile_fmode("[papr-vpd]", &papr_vpd_handle_ops,
+                                 (void *)blob, O_RDONLY,
+                                 FMODE_LSEEK | FMODE_PREAD);
        if (IS_ERR(file)) {
                err = PTR_ERR(file);
                goto put_fd;
        }
-
-       file->f_mode |= FMODE_LSEEK | FMODE_PREAD;
        fd_install(fd, file);
        return fd;
 put_fd:
index 49559605177efc1013691b452fd6a5a5c8f3380e..c321d442f0da090af34d818535c26b7b6d8f811b 100644 (file)
@@ -266,24 +266,12 @@ static struct file *vfio_device_open_file(struct vfio_device *device)
        if (ret)
                goto err_free;
 
-       /*
-        * We can't use anon_inode_getfd() because we need to modify
-        * the f_mode flags directly to allow more than just ioctls
-        */
-       filep = anon_inode_getfile("[vfio-device]", &vfio_device_fops,
-                                  df, O_RDWR);
+       filep = anon_inode_getfile_fmode("[vfio-device]", &vfio_device_fops,
+                                  df, O_RDWR, FMODE_PREAD | FMODE_PWRITE);
        if (IS_ERR(filep)) {
                ret = PTR_ERR(filep);
                goto err_close_device;
        }
-
-       /*
-        * TODO: add an anon_inode interface to do this.
-        * Appears to be missing by lack of need rather than
-        * explicitly prevented.  Now there's need.
-        */
-       filep->f_mode |= (FMODE_PREAD | FMODE_PWRITE);
-
        /*
         * Use the pseudo fs inode on the device to link all mmaps
         * to the same address space, allowing us to unmap all vmas
index fe3de9ad57bf6d5bb0115baa9a9c2cb61822b17a..d9bc6717612829e5777b441c51749d2d1ef107c1 100644 (file)
@@ -317,8 +317,9 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req,
                goto err_free_id;
        }
 
-       anon_file->file = anon_inode_getfile("[cachefiles]",
-                               &cachefiles_ondemand_fd_fops, object, O_WRONLY);
+       anon_file->file = anon_inode_getfile_fmode("[cachefiles]",
+                               &cachefiles_ondemand_fd_fops, object,
+                               O_WRONLY, FMODE_PWRITE | FMODE_LSEEK);
        if (IS_ERR(anon_file->file)) {
                ret = PTR_ERR(anon_file->file);
                goto err_put_fd;
@@ -333,8 +334,6 @@ static int cachefiles_ondemand_get_fd(struct cachefiles_req *req,
                goto err_put_file;
        }
 
-       anon_file->file->f_mode |= FMODE_PWRITE | FMODE_LSEEK;
-
        load = (void *)req->msg.data;
        load->fd = anon_file->fd;
        object->ondemand->ondemand_id = object_id;
index 76129bfcd663ace29546fc638654a48bea3a6c55..af42b2c7d2358c42841b6ea83a8e04866ab5750b 100644 (file)
@@ -406,14 +406,13 @@ static int do_eventfd(unsigned int count, int flags)
        if (fd < 0)
                goto err;
 
-       file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, flags);
+       file = anon_inode_getfile_fmode("[eventfd]", &eventfd_fops,
+                                       ctx, flags, FMODE_NOWAIT);
        if (IS_ERR(file)) {
                put_unused_fd(fd);
                fd = PTR_ERR(file);
                goto err;
        }
-
-       file->f_mode |= FMODE_NOWAIT;
        fd_install(fd, file);
        return fd;
 err:
index d1a5f43ce46692396137729c599a22d9b9ccce31..d469782f97f4d3cb8f4f39ea05aa8571c980331b 100644 (file)
@@ -277,15 +277,14 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags)
                        return ufd;
                }
 
-               file = anon_inode_getfile("[signalfd]", &signalfd_fops, ctx,
-                                      O_RDWR | (flags & O_NONBLOCK));
+               file = anon_inode_getfile_fmode("[signalfd]", &signalfd_fops,
+                                       ctx, O_RDWR | (flags & O_NONBLOCK),
+                                       FMODE_NOWAIT);
                if (IS_ERR(file)) {
                        put_unused_fd(ufd);
                        kfree(ctx);
                        return PTR_ERR(file);
                }
-               file->f_mode |= FMODE_NOWAIT;
-
                fd_install(ufd, file);
        } else {
                CLASS(fd, f)(ufd);
index 9f7eb451a60f611aa156db6beb75de0004efbbfb..753e22e83e0f74c87b68bde211a3e272ea317421 100644 (file)
@@ -439,15 +439,15 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
                return ufd;
        }
 
-       file = anon_inode_getfile("[timerfd]", &timerfd_fops, ctx,
-                                   O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS));
+       file = anon_inode_getfile_fmode("[timerfd]", &timerfd_fops, ctx,
+                           O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS),
+                           FMODE_NOWAIT);
        if (IS_ERR(file)) {
                put_unused_fd(ufd);
                kfree(ctx);
                return PTR_ERR(file);
        }
 
-       file->f_mode |= FMODE_NOWAIT;
        fd_install(ufd, file);
        return ufd;
 }
index faf10671eed2a39365855d54c05e8b03256cea00..d11cafd11aa3ab8fa78fb3e14539b0d37ec770a0 100644 (file)
@@ -4231,15 +4231,14 @@ static int kvm_vcpu_ioctl_get_stats_fd(struct kvm_vcpu *vcpu)
        if (fd < 0)
                return fd;
 
-       file = anon_inode_getfile(name, &kvm_vcpu_stats_fops, vcpu, O_RDONLY);
+       file = anon_inode_getfile_fmode(name, &kvm_vcpu_stats_fops, vcpu,
+                                       O_RDONLY, FMODE_PREAD);
        if (IS_ERR(file)) {
                put_unused_fd(fd);
                return PTR_ERR(file);
        }
 
        kvm_get_kvm(vcpu->kvm);
-
-       file->f_mode |= FMODE_PREAD;
        fd_install(fd, file);
 
        return fd;
@@ -5027,16 +5026,14 @@ static int kvm_vm_ioctl_get_stats_fd(struct kvm *kvm)
        if (fd < 0)
                return fd;
 
-       file = anon_inode_getfile("kvm-vm-stats",
-                       &kvm_vm_stats_fops, kvm, O_RDONLY);
+       file = anon_inode_getfile_fmode("kvm-vm-stats",
+                       &kvm_vm_stats_fops, kvm, O_RDONLY, FMODE_PREAD);
        if (IS_ERR(file)) {
                put_unused_fd(fd);
                return PTR_ERR(file);
        }
 
        kvm_get_kvm(kvm);
-
-       file->f_mode |= FMODE_PREAD;
        fd_install(fd, file);
 
        return fd;