diff mbox series

[2/5] block: refactor __bio_iov_bvec_add_pages

Message ID 20190411062331.27800-3-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/5] block: rewrite blk_bvec_map_sg to avoid a nth_page call | expand

Commit Message

Christoph Hellwig April 11, 2019, 6:23 a.m. UTC
Return early on error, and add an unlikely annotation for that case.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 block/bio.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Comments

Ming Lei April 11, 2019, 7:10 a.m. UTC | #1
On Thu, Apr 11, 2019 at 08:23:28AM +0200, Christoph Hellwig wrote:
> Return early on error, and add an unlikely annotation for that case.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
> ---
>  block/bio.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/block/bio.c b/block/bio.c
> index c2592c5d70b9..ad346082a971 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -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 *))
> -- 
> 2.20.1
> 

Reviewed-by: Ming Lei <ming.lei@redhat.com>
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index c2592c5d70b9..ad346082a971 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -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 *))