diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index a67bae350416..9983b940eb57 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -983,10 +983,8 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov, goto done; ret = io_buffer_account_pin(ctx, pages, nr_pages, imu, last_hpage); - if (ret) { - unpin_user_pages(pages, nr_pages); + if (ret) goto done; - } size = iov->iov_len; /* store original address for later verification */ @@ -1010,8 +1008,11 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov, size -= vec_len; } done: - if (ret) + if (ret) { kvfree(imu); + if (pages) + unpin_user_pages(pages, nr_pages); + } kvfree(pages); return ret; }