Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/rsrc: cleanup io_pin_pages()

This function is overly convoluted with a goto error path, and checks
under the mmap_read_lock() that don't need to be at all. Rearrange it
a bit so the checks and errors fall out naturally, rather than needing
to jump around for it.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

+18 -21
+18 -21
io_uring/rsrc.c
··· 1037 1037 { 1038 1038 unsigned long start, end, nr_pages; 1039 1039 struct page **pages = NULL; 1040 - int pret, ret = -ENOMEM; 1040 + int ret; 1041 1041 1042 1042 end = (ubuf + len + PAGE_SIZE - 1) >> PAGE_SHIFT; 1043 1043 start = ubuf >> PAGE_SHIFT; 1044 1044 nr_pages = end - start; 1045 + WARN_ON(!nr_pages); 1045 1046 1046 1047 pages = kvmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL); 1047 1048 if (!pages) 1048 - goto done; 1049 + return ERR_PTR(-ENOMEM); 1049 1050 1050 - ret = 0; 1051 1051 mmap_read_lock(current->mm); 1052 - pret = pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM, 1053 - pages); 1054 - if (pret == nr_pages) 1055 - *npages = nr_pages; 1056 - else 1057 - ret = pret < 0 ? pret : -EFAULT; 1058 - 1052 + ret = pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM, pages); 1059 1053 mmap_read_unlock(current->mm); 1060 - if (ret) { 1054 + 1055 + /* success, mapped all pages */ 1056 + if (ret == nr_pages) { 1057 + *npages = nr_pages; 1058 + return pages; 1059 + } 1060 + 1061 + /* partial map, or didn't map anything */ 1062 + if (ret >= 0) { 1061 1063 /* if we did partial map, release any pages we did get */ 1062 - if (pret > 0) 1063 - unpin_user_pages(pages, pret); 1064 - goto done; 1064 + if (ret) 1065 + unpin_user_pages(pages, ret); 1066 + ret = -EFAULT; 1065 1067 } 1066 - ret = 0; 1067 - done: 1068 - if (ret < 0) { 1069 - kvfree(pages); 1070 - pages = ERR_PTR(ret); 1071 - } 1072 - return pages; 1068 + kvfree(pages); 1069 + return ERR_PTR(ret); 1073 1070 } 1074 1071 1075 1072 static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,