Rely on the fd exit path machinery.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 io_uring/zcrx.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 1b3b11405dac..d458c614c765 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -795,8 +795,6 @@ static int zcrx_export(struct io_ring_ctx *ctx, struct 
io_zcrx_ifq *ifq,
                       struct zcrx_ctrl *ctrl, void __user *arg)
 {
        struct zcrx_ctrl_export *ce = &ctrl->zc_export;
-       struct file *file;
-       int fd;
 
        if (!mem_is_zero(ce, sizeof(*ce)))
                return -EINVAL;
@@ -804,27 +802,18 @@ static int zcrx_export(struct io_ring_ctx *ctx, struct 
io_zcrx_ifq *ifq,
        refcount_inc(&ifq->refs);
        refcount_inc(&ifq->user_refs);
 
-       file = anon_inode_create_getfile("[zcrx]", &zcrx_box_fops,
-                                        ifq, O_CLOEXEC, NULL);
-       if (IS_ERR(file)) {
+       FD_PREPARE(fdf, O_CLOEXEC,
+                  anon_inode_create_getfile("[zcrx]", &zcrx_box_fops, ifq,
+                                            O_CLOEXEC, NULL));
+       if (IS_ERR(fdf)) {
                zcrx_unregister(ifq, NULL);
-               return PTR_ERR(file);
-       }
-
-       fd = get_unused_fd_flags(O_CLOEXEC);
-       if (fd < 0) {
-               fput(file);
-               return fd;
+               return PTR_ERR(fdf);
        }
 
-       ce->zcrx_fd = fd;
-       if (copy_to_user(arg, ctrl, sizeof(*ctrl))) {
-               fput(file);
-               put_unused_fd(fd);
+       ce->zcrx_fd = fd_prepare_fd(fdf);
+       if (copy_to_user(arg, ctrl, sizeof(*ctrl)))
                return -EFAULT;
-       }
 
-       fd_install(fd, file);
        return 0;
 }
 

-- 
2.53.0


Reply via email to