diff mbox series

[V2] block: fix build warning in merging bvecs

Message ID 20190402022644.7812-1-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series [V2] block: fix build warning in merging bvecs | expand

Commit Message

Ming Lei April 2, 2019, 2:26 a.m. UTC
Commit f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can
be mergeable") changes bvec merge by only considering two bvecs from
different bios. However, if the former bio doesn't inlcude any io bvec,
then the following warning may be triggered:

 warning: ‘bvec.bv_offset’ may be used uninitialized in this function [-Wmaybe-uninitialized]

In practice, it shouldn't be triggered.

Fixes it by adding check on former bio, the check shouldn't add any cost
given 'bio->bi_iter' can be hit in cache.

Reported-by: Jens Axboe <axboe@kernel.dk>
Fixes: f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can be mergeable")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-merge.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Jens Axboe April 8, 2019, 4:57 p.m. UTC | #1
On 4/1/19 8:26 PM, Ming Lei wrote:
> Commit f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can
> be mergeable") changes bvec merge by only considering two bvecs from
> different bios. However, if the former bio doesn't inlcude any io bvec,
> then the following warning may be triggered:
> 
>  warning: ‘bvec.bv_offset’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> In practice, it shouldn't be triggered.
> 
> Fixes it by adding check on former bio, the check shouldn't add any cost
> given 'bio->bi_iter' can be hit in cache.

Applied, thanks.
diff mbox series

Patch

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 8f96d683b577..895795cdb145 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -353,7 +353,7 @@  EXPORT_SYMBOL(blk_queue_split);
 static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
 					     struct bio *bio)
 {
-	struct bio_vec bv, bvprv = { NULL };
+	struct bio_vec uninitialized_var(bv), bvprv = { NULL };
 	unsigned int seg_size, nr_phys_segs;
 	unsigned front_seg_size;
 	struct bio *fbio, *bbio;
@@ -400,8 +400,10 @@  static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
 			new_bio = false;
 		}
 		bbio = bio;
-		bvprv = bv;
-		new_bio = true;
+		if (likely(bio->bi_iter.bi_size)) {
+			bvprv = bv;
+			new_bio = true;
+		}
 	}
 
 	fbio->bi_seg_front_size = front_seg_size;
@@ -527,7 +529,7 @@  static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
 			     struct scatterlist *sglist,
 			     struct scatterlist **sg)
 {
-	struct bio_vec bvec, bvprv = { NULL };
+	struct bio_vec uninitialized_var(bvec), bvprv = { NULL };
 	struct bvec_iter iter;
 	int nsegs = 0;
 	bool new_bio = false;
@@ -550,8 +552,10 @@  static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
  next_bvec:
 			new_bio = false;
 		}
-		bvprv = bvec;
-		new_bio = true;
+		if (likely(bio->bi_iter.bi_size)) {
+			bvprv = bvec;
+			new_bio = true;
+		}
 	}
 
 	return nsegs;