]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
io_uring/register: don't get a reference to the registered ring fd
authorJens Axboe <axboe@kernel.dk>
Wed, 8 Apr 2026 17:50:08 +0000 (11:50 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 8 Apr 2026 19:21:35 +0000 (13:21 -0600)
This isn't necessary and was only done because the register path isn't a
hot path and hence the extra ref/put doesn't matter, and to have the
exit path be able to unconditionally put whatever file was gotten
regardless of the type.

In preparation for sharing this code with the main io_uring_enter(2)
syscall, drop the reference and have the caller conditionally put the
file if it was a normal file descriptor.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/register.c
io_uring/rsrc.c

index 35432471a550f393a6cf60a8f10bfd182413b8bc..95cfa88dc621f4bcdac9393038a38957e0abe789 100644 (file)
@@ -941,7 +941,8 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
 /*
  * Given an 'fd' value, return the ctx associated with if. If 'registered' is
  * true, then the registered index is used. Otherwise, the normal fd table.
- * Caller must call fput() on the returned file, unless it's an ERR_PTR.
+ * Caller must call fput() on the returned file if it isn't a registered file,
+ * unless it's an ERR_PTR.
  */
 struct file *io_uring_register_get_file(unsigned int fd, bool registered)
 {
@@ -958,8 +959,6 @@ 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);
        }
@@ -1038,6 +1037,7 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
                                ctx->buf_table.nr, ret);
        mutex_unlock(&ctx->uring_lock);
 
-       fput(file);
+       if (!use_registered_ring)
+               fput(file);
        return ret;
 }
index 2d8be5edbbf6eb6ce1d56e5c49f271b58c9be17d..cb12194b35e8f1626893a4976019bc54c82f3adc 100644 (file)
@@ -1291,7 +1291,8 @@ out:
        if (src_ctx != ctx)
                mutex_unlock(&src_ctx->uring_lock);
 
-       fput(file);
+       if (!registered_src)
+               fput(file);
        return ret;
 }