block: refactor __bio_iov_bvec_add_pages
authorChristoph Hellwig <hch@lst.de>
Thu, 11 Apr 2019 06:23:28 +0000 (08:23 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 12 Apr 2019 15:06:37 +0000 (09:06 -0600)
Return early on error, and add an unlikely annotation for that case.

Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c

index c2592c5d70b98751a4b6e26c40938afc33a4869b..ad346082a9719034a586ebf031c7848ee8aa4bc4 100644 (file)
@@ -873,20 +873,19 @@ static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter)
        len = min_t(size_t, bv->bv_len - iter->iov_offset, iter->count);
        size = bio_add_page(bio, bv->bv_page, len,
                                bv->bv_offset + iter->iov_offset);
-       if (size == len) {
-               if (!bio_flagged(bio, BIO_NO_PAGE_REF)) {
-                       struct page *page;
-                       int i;
+       if (unlikely(size != len))
+               return -EINVAL;
 
-                       mp_bvec_for_each_page(page, bv, i)
-                               get_page(page);
-               }
+       if (!bio_flagged(bio, BIO_NO_PAGE_REF)) {
+               struct page *page;
+               int i;
 
-               iov_iter_advance(iter, size);
-               return 0;
+               mp_bvec_for_each_page(page, bv, i)
+                       get_page(page);
        }
 
-       return -EINVAL;
+       iov_iter_advance(iter, size);
+       return 0;
 }
 
 #define PAGE_PTRS_PER_BVEC     (sizeof(struct bio_vec) / sizeof(struct page *))