]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vfio: convert vfio_group_ioctl_get_device_fd() to FD_ADD()
authorChristian Brauner <brauner@kernel.org>
Sun, 23 Nov 2025 16:34:01 +0000 (17:34 +0100)
committerChristian Brauner <brauner@kernel.org>
Fri, 28 Nov 2025 11:42:36 +0000 (12:42 +0100)
Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-43-b6efa1706cfd@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
drivers/vfio/group.c

index c376a6279de0e63f3794851ccb9988d289ee3866..d47ffada69126f2823d7aa571be6cdabdec2a8ff 100644 (file)
@@ -299,10 +299,8 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
                                          char __user *arg)
 {
        struct vfio_device *device;
-       struct file *filep;
        char *buf;
-       int fdno;
-       int ret;
+       int fd;
 
        buf = strndup_user(arg, PAGE_SIZE);
        if (IS_ERR(buf))
@@ -313,26 +311,10 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
        if (IS_ERR(device))
                return PTR_ERR(device);
 
-       fdno = get_unused_fd_flags(O_CLOEXEC);
-       if (fdno < 0) {
-               ret = fdno;
-               goto err_put_device;
-       }
-
-       filep = vfio_device_open_file(device);
-       if (IS_ERR(filep)) {
-               ret = PTR_ERR(filep);
-               goto err_put_fdno;
-       }
-
-       fd_install(fdno, filep);
-       return fdno;
-
-err_put_fdno:
-       put_unused_fd(fdno);
-err_put_device:
-       vfio_device_put_registration(device);
-       return ret;
+       fd = FD_ADD(O_CLOEXEC, vfio_device_open_file(device));
+       if (fd < 0)
+               vfio_device_put_registration(device);
+       return fd;
 }
 
 static int vfio_group_ioctl_get_status(struct vfio_group *group,