Skip to content

Commit 5f3ea1c

Browse files
committed
vfio: convert vfio_group_ioctl_get_device_fd() to FD_ADD()
Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-43-b6efa1706cfd@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 3fd5edf commit 5f3ea1c

1 file changed

Lines changed: 5 additions & 23 deletions

File tree

drivers/vfio/group.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,8 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
299299
char __user *arg)
300300
{
301301
struct vfio_device *device;
302-
struct file *filep;
303302
char *buf;
304-
int fdno;
305-
int ret;
303+
int fd;
306304

307305
buf = strndup_user(arg, PAGE_SIZE);
308306
if (IS_ERR(buf))
@@ -313,26 +311,10 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
313311
if (IS_ERR(device))
314312
return PTR_ERR(device);
315313

316-
fdno = get_unused_fd_flags(O_CLOEXEC);
317-
if (fdno < 0) {
318-
ret = fdno;
319-
goto err_put_device;
320-
}
321-
322-
filep = vfio_device_open_file(device);
323-
if (IS_ERR(filep)) {
324-
ret = PTR_ERR(filep);
325-
goto err_put_fdno;
326-
}
327-
328-
fd_install(fdno, filep);
329-
return fdno;
330-
331-
err_put_fdno:
332-
put_unused_fd(fdno);
333-
err_put_device:
334-
vfio_device_put_registration(device);
335-
return ret;
314+
fd = FD_ADD(O_CLOEXEC, vfio_device_open_file(device));
315+
if (fd < 0)
316+
vfio_device_put_registration(device);
317+
return fd;
336318
}
337319

338320
static int vfio_group_ioctl_get_status(struct vfio_group *group,

0 commit comments

Comments
 (0)