Skip to content

Commit bb2d763

Browse files
isilenceaxboe
authored andcommitted
io_uring: clean up io_uring_register_get_file()
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 <[email protected]> Link: https://lore.kernel.org/r/0d0b13a63e8edd6b5d360fc821dcdb035cb6b7e0.1736995897.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 5719e28 commit bb2d763

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

io_uring/register.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,8 @@ struct file *io_uring_register_get_file(unsigned int fd, bool registered)
853853
return ERR_PTR(-EINVAL);
854854
fd = array_index_nospec(fd, IO_RINGFD_REG_MAX);
855855
file = tctx->registered_rings[fd];
856+
if (file)
857+
get_file(file);
856858
} else {
857859
file = fget(fd);
858860
}
@@ -919,7 +921,7 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
919921
trace_io_uring_register(ctx, opcode, ctx->file_table.data.nr,
920922
ctx->buf_table.nr, ret);
921923
mutex_unlock(&ctx->uring_lock);
922-
if (!use_registered_ring)
923-
fput(file);
924+
925+
fput(file);
924926
return ret;
925927
}

io_uring/rsrc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,6 @@ int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg)
10791079
if (src_ctx != ctx)
10801080
mutex_unlock(&src_ctx->uring_lock);
10811081

1082-
if (!registered_src)
1083-
fput(file);
1082+
fput(file);
10841083
return ret;
10851084
}

0 commit comments

Comments
 (0)