Skip to contentSkip to conversation

block: fix build warning in __blk_bios_map_sg()

PATCH Superseded Ming Lei 1 participant 2 messages Apr 2, 2019 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block: fix build warning in __blk_bios_map_sg()

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.

Fixes f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can be mergeable")
---
 block/blk-merge.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
block/blk-merge.c +5 -3
index 8f96d683b577..1fc66d03893f 100644
@@ -527,7 +527,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 +550,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;
Signature · 1 line
2.9.5
author
#1 lore raw
Quoted 33 lines · Ming Lei

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.

Fixes f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can be mergeable")
---
 block/blk-merge.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
block/blk-merge.c +1 -1
index 8f96d683b577..1fc66d03893f 100644
@@ -527,7 +527,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;

block/blk-merge.c static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio, · line 557

Quoted 10 lines
block/blk-merge.c +4 -2
@@ -550,8 +550,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;
+		}
 	}

Looks __blk_recalc_rq_segments() needs the similar fix too, so please ignore this one, and I will handle them all in one patch.

Thanks,
Ming