]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
io_uring/zcrx: fully clean area on error in io_import_umem()
authorPavel Begunkov <asml.silence@gmail.com>
Mon, 23 Mar 2026 12:43:51 +0000 (12:43 +0000)
committerJens Axboe <axboe@kernel.dk>
Wed, 1 Apr 2026 16:21:12 +0000 (10:21 -0600)
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 <asml.silence@gmail.com>
Link: https://patch.msgid.link/3a602b7fb347dbd4da6797ac49b52ea5dedb856d.1774261953.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/zcrx.c

index 615805d2c3dd0f0348023e5a68973a3ebcb7ddbd..2f60193365ce87875c246206cb7863c58893e12c 100644 (file)
@@ -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)