Skip to content

Commit 4104156

Browse files
isilenceaxboe
authored andcommitted
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 <asml.silence@gmail.com> Link: https://patch.msgid.link/3a602b7fb347dbd4da6797ac49b52ea5dedb856d.1774261953.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e5361d2 commit 4104156

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

io_uring/zcrx.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,26 @@ static int io_import_umem(struct io_zcrx_ifq *ifq,
207207
ret = sg_alloc_table_from_pages(&mem->page_sg_table, pages, nr_pages,
208208
0, (unsigned long)nr_pages << PAGE_SHIFT,
209209
GFP_KERNEL_ACCOUNT);
210-
if (ret) {
211-
unpin_user_pages(pages, nr_pages);
212-
kvfree(pages);
213-
return ret;
214-
}
210+
if (ret)
211+
goto out_err;
215212

216213
mem->account_pages = io_count_account_pages(pages, nr_pages);
217214
ret = io_account_mem(ifq->user, ifq->mm_account, mem->account_pages);
218-
if (ret < 0)
215+
if (ret < 0) {
219216
mem->account_pages = 0;
217+
goto out_err;
218+
}
220219

221220
mem->sgt = &mem->page_sg_table;
222221
mem->pages = pages;
223222
mem->nr_folios = nr_pages;
224223
mem->size = area_reg->len;
225224
return ret;
225+
out_err:
226+
sg_free_table(&mem->page_sg_table);
227+
unpin_user_pages(pages, nr_pages);
228+
kvfree(pages);
229+
return ret;
226230
}
227231

228232
static void io_release_area_mem(struct io_zcrx_mem *mem)

0 commit comments

Comments
 (0)