Skip to content

Commit b4d893d

Browse files
committed
io_uring/register: don't get a reference to the registered ring fd
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>
1 parent 7880174 commit b4d893d

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

io_uring/register.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,8 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
941941
/*
942942
* Given an 'fd' value, return the ctx associated with if. If 'registered' is
943943
* true, then the registered index is used. Otherwise, the normal fd table.
944-
* Caller must call fput() on the returned file, unless it's an ERR_PTR.
944+
* Caller must call fput() on the returned file if it isn't a registered file,
945+
* unless it's an ERR_PTR.
945946
*/
946947
struct file *io_uring_register_get_file(unsigned int fd, bool registered)
947948
{
@@ -958,8 +959,6 @@ struct file *io_uring_register_get_file(unsigned int fd, bool registered)
958959
return ERR_PTR(-EINVAL);
959960
fd = array_index_nospec(fd, IO_RINGFD_REG_MAX);
960961
file = tctx->registered_rings[fd];
961-
if (file)
962-
get_file(file);
963962
} else {
964963
file = fget(fd);
965964
}
@@ -1038,6 +1037,7 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
10381037
ctx->buf_table.nr, ret);
10391038
mutex_unlock(&ctx->uring_lock);
10401039

1041-
fput(file);
1040+
if (!use_registered_ring)
1041+
fput(file);
10421042
return ret;
10431043
}

io_uring/rsrc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,8 @@ int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg)
12911291
if (src_ctx != ctx)
12921292
mutex_unlock(&src_ctx->uring_lock);
12931293

1294-
fput(file);
1294+
if (!registered_src)
1295+
fput(file);
12951296
return ret;
12961297
}
12971298

0 commit comments

Comments
 (0)