Skip to content

Commit

Permalink
block: refactor __bio_iov_bvec_add_pages
Browse files Browse the repository at this point in the history
Return early on error, and add an unlikely annotation for that case.

Reviewed-by: Ming Lei <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Bart Van Assche <[email protected]>
Reviewed-by: Johannes Thumshirn <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Apr 12, 2019
1 parent 8a96a0e commit a10584c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *))
Expand Down

0 comments on commit a10584c

Please sign in to comment.