]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
io_uring: don't prepare DRAIN reqs twice
authorPavel Begunkov <asml.silence@gmail.com>
Sun, 17 May 2020 11:02:11 +0000 (14:02 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 7 Jun 2020 11:16:46 +0000 (13:16 +0200)
[ Upstream commit 650b548129b60b0d23508351800108196f4aa89f ]

If req->io is not NULL, it's already prepared. Don't do it again,
it's dangerous.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/io_uring.c

index 8bdf2629f7fdd0f811f398347077fce2f5480602..aa800f70c55ed4658582f9c32ad98ae94559a5b1 100644 (file)
@@ -4262,12 +4262,13 @@ static int io_req_defer(struct io_kiocb *req, const struct io_uring_sqe *sqe)
        if (!req_need_defer(req) && list_empty_careful(&ctx->defer_list))
                return 0;
 
-       if (!req->io && io_alloc_async_ctx(req))
-               return -EAGAIN;
-
-       ret = io_req_defer_prep(req, sqe);
-       if (ret < 0)
-               return ret;
+       if (!req->io) {
+               if (io_alloc_async_ctx(req))
+                       return -EAGAIN;
+               ret = io_req_defer_prep(req, sqe);
+               if (ret < 0)
+                       return ret;
+       }
 
        spin_lock_irq(&ctx->completion_lock);
        if (!req_need_defer(req) && list_empty(&ctx->defer_list)) {