If futex_wait_setup() fails in io_futex_wait(), Old code just releases io_futex_data. This patch tries to cache io_futex_data before kfree. Signed-off-by: Sidong Yang <sidong.yang@xxxxxxxxxx> --- io_uring/futex.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/io_uring/futex.c b/io_uring/futex.c index e29662f039e1..217a38498c36 100644 --- a/io_uring/futex.c +++ b/io_uring/futex.c @@ -262,6 +262,13 @@ static struct io_futex_data *io_alloc_ifd(struct io_ring_ctx *ctx) return kmalloc(sizeof(struct io_futex_data), GFP_NOWAIT); } +static void io_free_ifd(struct io_ring_ctx *ctx, struct io_futex_data *ifd) +{ + if (!io_alloc_cache_put(&ctx->futex_cache, ifd)) { + kfree(ifd); + } +} + int io_futexv_wait(struct io_kiocb *req, unsigned int issue_flags) { struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex); @@ -353,13 +360,13 @@ int io_futex_wait(struct io_kiocb *req, unsigned int issue_flags) return IOU_ISSUE_SKIP_COMPLETE; } + io_free_ifd(ctx, ifd); done_unlock: io_ring_submit_unlock(ctx, issue_flags); done: if (ret < 0) req_set_fail(req); io_req_set_res(req, ret, 0); - kfree(ifd); return IOU_OK; } -- 2.43.0