diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index d610e0f96844..7ac9eb6a0934 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -698,19 +698,10 @@ static int zcrx_export(struct io_ring_ctx *ctx, struct io_zcrx_ifq *ifq, { struct zcrx_ctrl_export *ce = &ctrl->zc_export; struct file *file; - int fd = -1; + int fd; if (!mem_is_zero(ce, sizeof(*ce))) return -EINVAL; - fd = get_unused_fd_flags(O_CLOEXEC); - if (fd < 0) - return fd; - - ce->zcrx_fd = fd; - if (copy_to_user(arg, ctrl, sizeof(*ctrl))) { - put_unused_fd(fd); - return -EFAULT; - } refcount_inc(&ifq->refs); refcount_inc(&ifq->user_refs); @@ -718,11 +709,23 @@ static int zcrx_export(struct io_ring_ctx *ctx, struct io_zcrx_ifq *ifq, file = anon_inode_create_getfile("[zcrx]", &zcrx_box_fops, ifq, O_CLOEXEC, NULL); if (IS_ERR(file)) { - put_unused_fd(fd); zcrx_unregister(ifq); return PTR_ERR(file); } + fd = get_unused_fd_flags(O_CLOEXEC); + if (fd < 0) { + fput(file); + return fd; + } + + ce->zcrx_fd = fd; + if (copy_to_user(arg, ctrl, sizeof(*ctrl))) { + fput(file); + put_unused_fd(fd); + return -EFAULT; + } + fd_install(fd, file); return 0; }