]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
io_uring: clean up io_uring_register_get_file()
authorPavel Begunkov <asml.silence@gmail.com>
Thu, 16 Jan 2025 02:53:26 +0000 (02:53 +0000)
committerJens Axboe <axboe@kernel.dk>
Tue, 21 Jan 2025 14:07:17 +0000 (07:07 -0700)
Make it always reference the returned file. It's safer, especially with
unregistrations happening under it. And it makes the api cleaner with no
conditional clean ups by the caller.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/0d0b13a63e8edd6b5d360fc821dcdb035cb6b7e0.1736995897.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/register.c
io_uring/rsrc.c

index 05025047d1daba1366e77346e844a3ee23533292..0db181437ae3305e2e26bbd99192c6143132c17c 100644 (file)
@@ -853,6 +853,8 @@ struct file *io_uring_register_get_file(unsigned int fd, bool registered)
                        return ERR_PTR(-EINVAL);
                fd = array_index_nospec(fd, IO_RINGFD_REG_MAX);
                file = tctx->registered_rings[fd];
+               if (file)
+                       get_file(file);
        } else {
                file = fget(fd);
        }
@@ -919,7 +921,7 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
        trace_io_uring_register(ctx, opcode, ctx->file_table.data.nr,
                                ctx->buf_table.nr, ret);
        mutex_unlock(&ctx->uring_lock);
-       if (!use_registered_ring)
-               fput(file);
+
+       fput(file);
        return ret;
 }
index a1c7c8db55455e6db862a17ed611f3d6ce885b3d..b5e47030764e569aab6184351a391fab8efbc584 100644 (file)
@@ -1079,7 +1079,6 @@ int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg)
        if (src_ctx != ctx)
                mutex_unlock(&src_ctx->uring_lock);
 
-       if (!registered_src)
-               fput(file);
+       fput(file);
        return ret;
 }