Skip to contentSkip to conversation

block: avoid to READ fields of null bio

PATCH New Ming Lei 1 participant 1 message Feb 19, 2019 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block: avoid to READ fields of null bio

rq->bio can be NULL sometimes, such as flush request, so don't read bio->bi_seg_front_size until this 'bio' is checked as valid.

Cc Bart Van Assche <[email protected]>
Fixes dcebd755926b0f39dd1e ("block: use bio_for_each_bvec() to compute multi-page bvec count")
---
 block/blk-merge.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-merge.c +3 -1
index bed065904677..066b66430523 100644
@@ -363,13 +363,15 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
 	struct bio_vec bv, bvprv = { NULL };
 	int prev = 0;
 	unsigned int seg_size, nr_phys_segs;
-	unsigned front_seg_size = bio->bi_seg_front_size;
+	unsigned front_seg_size;
 	struct bio *fbio, *bbio;
 	struct bvec_iter iter;
 
 	if (!bio)
 		return 0;
 
+	front_seg_size = bio->bi_seg_front_size;
+
 	switch (bio_op(bio)) {
 	case REQ_OP_DISCARD:
 	case REQ_OP_SECURE_ERASE:
Signature · 1 line
2.9.5