From: Pavel Begunkov Date: Mon, 23 Mar 2026 12:43:51 +0000 (+0000) Subject: io_uring/zcrx: fully clean area on error in io_import_umem() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41041562a7d6acd5a8ce918be8da7e26337f379f;p=thirdparty%2Fkernel%2Flinux.git io_uring/zcrx: fully clean area on error in io_import_umem() When accounting fails, io_import_umem() sets the page array, etc. and returns an error expecting that the error handling code will take care of the rest. To make the next patch simpler, only return a fully initialised areas from the function. Signed-off-by: Pavel Begunkov Link: https://patch.msgid.link/3a602b7fb347dbd4da6797ac49b52ea5dedb856d.1774261953.git.asml.silence@gmail.com Signed-off-by: Jens Axboe --- diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 615805d2c3dd0..2f60193365ce8 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -207,22 +207,26 @@ static int io_import_umem(struct io_zcrx_ifq *ifq, ret = sg_alloc_table_from_pages(&mem->page_sg_table, pages, nr_pages, 0, (unsigned long)nr_pages << PAGE_SHIFT, GFP_KERNEL_ACCOUNT); - if (ret) { - unpin_user_pages(pages, nr_pages); - kvfree(pages); - return ret; - } + if (ret) + goto out_err; mem->account_pages = io_count_account_pages(pages, nr_pages); ret = io_account_mem(ifq->user, ifq->mm_account, mem->account_pages); - if (ret < 0) + if (ret < 0) { mem->account_pages = 0; + goto out_err; + } mem->sgt = &mem->page_sg_table; mem->pages = pages; mem->nr_folios = nr_pages; mem->size = area_reg->len; return ret; +out_err: + sg_free_table(&mem->page_sg_table); + unpin_user_pages(pages, nr_pages); + kvfree(pages); + return ret; } static void io_release_area_mem(struct io_zcrx_mem *mem)