summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2022-04-07 13:40:02 +0100
committerJens Axboe <axboe@kernel.dk>2022-04-24 17:34:19 -0600
commitdca58c6a08a92c5c674140047de7f72f9cc843d0 (patch)
tree0d57268d09b6184050cd295ebf58b58bfc5153a9
parenta03a2a209e826f646dff49202b8b1eb8427c2d08 (diff)
downloadlwn-dca58c6a08a92c5c674140047de7f72f9cc843d0.tar.gz
lwn-dca58c6a08a92c5c674140047de7f72f9cc843d0.zip
io_uring: refactor __io_sqe_files_scm
__io_sqe_files_scm() is now called only from one place passing a single file, so nr argument can be killed and __io_sqe_files_scm() simplified. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/66b492bc66dc8356d45d64076bb31d677d11a7c9.1649334991.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--fs/io_uring.c48
1 files changed, 13 insertions, 35 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index a9c8bf49552a..cbc8ddb23181 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8609,12 +8609,12 @@ static struct io_sq_data *io_get_sq_data(struct io_uring_params *p,
* files because otherwise they can't form a loop and so are not interesting
* for GC.
*/
-static int __io_sqe_files_scm(struct io_ring_ctx *ctx, int nr, int offset)
+static int __io_sqe_files_scm(struct io_ring_ctx *ctx, int offset)
{
+ struct file *file = io_file_from_index(ctx, offset);
struct sock *sk = ctx->ring_sock->sk;
struct scm_fp_list *fpl;
struct sk_buff *skb;
- int i, nr_files;
fpl = kzalloc(sizeof(*fpl), GFP_KERNEL);
if (!fpl)
@@ -8628,39 +8628,17 @@ static int __io_sqe_files_scm(struct io_ring_ctx *ctx, int nr, int offset)
skb->sk = sk;
- nr_files = 0;
fpl->user = get_uid(current_user());
- for (i = 0; i < nr; i++) {
- struct file *file = io_file_from_index(ctx, i + offset);
-
- if (!file || !io_file_need_scm(file))
- continue;
-
- fpl->fp[nr_files] = get_file(file);
- unix_inflight(fpl->user, fpl->fp[nr_files]);
- nr_files++;
- }
-
- if (nr_files) {
- fpl->max = SCM_MAX_FD;
- fpl->count = nr_files;
- UNIXCB(skb).fp = fpl;
- skb->destructor = unix_destruct_scm;
- refcount_add(skb->truesize, &sk->sk_wmem_alloc);
- skb_queue_head(&sk->sk_receive_queue, skb);
-
- for (i = 0; i < nr; i++) {
- struct file *file = io_file_from_index(ctx, i + offset);
-
- if (file && io_file_need_scm(file))
- fput(file);
- }
- } else {
- kfree_skb(skb);
- free_uid(fpl->user);
- kfree(fpl);
- }
-
+ fpl->fp[0] = get_file(file);
+ unix_inflight(fpl->user, file);
+
+ fpl->max = SCM_MAX_FD;
+ fpl->count = 1;
+ UNIXCB(skb).fp = fpl;
+ skb->destructor = unix_destruct_scm;
+ refcount_add(skb->truesize, &sk->sk_wmem_alloc);
+ skb_queue_head(&sk->sk_receive_queue, skb);
+ fput(file);
return 0;
}
#endif
@@ -8904,7 +8882,7 @@ static int io_sqe_file_register(struct io_ring_ctx *ctx, struct file *file,
return 0;
}
- return __io_sqe_files_scm(ctx, 1, index);
+ return __io_sqe_files_scm(ctx, index);
#else
return 0;
#endif