Rely on the fd exit path machinery. Signed-off-by: Christian Brauner (Amutable) --- drivers/hv/mshv_root_main.c | 27 +++++++-------------------- drivers/hv/mshv_vtl_main.c | 20 +++++--------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index cc2cfce2aefd..c95cee0bae85 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -1072,8 +1072,6 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition, struct mshv_vp *vp; struct page *intercept_msg_page, *register_page, *ghcb_page; struct hv_stats_page *stats_pages[2]; - struct file *file; - int fd; long ret; if (copy_from_user(&args, arg, sizeof(args))) @@ -1148,19 +1146,14 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition, if (ret) goto put_partition; - fd = get_unused_fd_flags(O_RDWR | O_CLOEXEC); - if (fd < 0) { - ret = fd; + FD_PREPARE(fdf, O_RDWR | O_CLOEXEC, + anon_inode_getfile("mshv_vp", &mshv_vp_fops, vp, + O_RDWR | O_CLOEXEC)); + if (IS_ERR(fdf)) { + ret = PTR_ERR(fdf); goto remove_debugfs_vp; } - file = anon_inode_getfile("mshv_vp", &mshv_vp_fops, vp, - O_RDWR | O_CLOEXEC); - if (IS_ERR(file)) { - ret = PTR_ERR(file); - goto put_unused_vp_fd; - } - /* already exclusive with the partition mutex for all ioctls */ partition->pt_vp_count++; /* @@ -1171,17 +1164,11 @@ mshv_partition_ioctl_create_vp(struct mshv_partition *partition, */ smp_store_release(&partition->pt_vp_array[args.vp_index], vp); - /* - * fd_install() is the userspace-visibility commit point. Must be the - * last operation that can fail or be observed. - */ - fd_install(fd, file); - ret = fd; + /* The syscall exit installs the file; nothing after this can fail. */ + ret = fd_prepare_fd(fdf); goto out; -put_unused_vp_fd: - put_unused_fd(fd); remove_debugfs_vp: mshv_debugfs_vp_remove(vp); put_partition: diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c index 6e3c11c68171..f14203d76da1 100644 --- a/drivers/hv/mshv_vtl_main.c +++ b/drivers/hv/mshv_vtl_main.c @@ -114,29 +114,19 @@ static long mshv_ioctl_create_vtl(void __user *user_arg, struct device *module_dev) { struct mshv_vtl *vtl; - struct file *file; - int fd; vtl = kzalloc_obj(*vtl); if (!vtl) return -ENOMEM; - fd = get_unused_fd_flags(O_CLOEXEC); - if (fd < 0) { - kfree(vtl); - return fd; - } - file = anon_inode_getfile("mshv_vtl", &mshv_vtl_fops, - vtl, O_RDWR); - if (IS_ERR(file)) { - put_unused_fd(fd); + FD_PREPARE(fdf, O_CLOEXEC, + anon_inode_getfile("mshv_vtl", &mshv_vtl_fops, vtl, O_RDWR)); + if (IS_ERR(fdf)) { kfree(vtl); - return PTR_ERR(file); + return PTR_ERR(fdf); } vtl->module_dev = module_dev; - fd_install(fd, file); - - return fd; + return fd_prepare_fd(fdf); } static long -- 2.53.0