Subject: [PATCH 1523/2944] io_uring: fix flush req->refs underflow

From: Pavel Begunkov <[email-masked]>
Date: Tue, 26 May 2020 20:34:02 +0300

to #28736503

commit 4518a3cc273cf82efdd36522fb1f13baad173c70 upstream

In io_uring_cancel_files(), after refcount_sub_and_test() leaves 0
req->refs, it calls io_put_req(), which would also put a ref. Call
io_free_req() instead.

Cc: [email-masked]
Fixes: 2ca10259b418 ("io_uring: prune request from overflow list on flush")
Signed-off-by: Pavel Begunkov <[email-masked]>
Signed-off-by: Jens Axboe <[email-masked]>
Signed-off-by: Xiaoguang Wang <[email-masked]>
Acked-by: Joseph Qi <[email-masked]>
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index d1715ba..2434ea5 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7446,7 +7446,7 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
 			 * all we had, then we're done with this request.
 			 */
 			if (refcount_sub_and_test(2, &cancel_req->refs)) {
-				io_put_req(cancel_req);
+				io_free_req(cancel_req);
 				finish_wait(&ctx->inflight_wait, &wait);
 				continue;
 			}
-- 
1.8.3.1