From: Keith Busch Date: Tue, 11 Nov 2025 14:06:20 +0000 (-0800) Subject: block: fix merging data-less bios X-Git-Tag: v6.19-rc1~168^2~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd9ecd005252b595fd02ff7fcc4056251027404d;p=thirdparty%2Fkernel%2Flinux.git block: fix merging data-less bios The data segment gaps the block layer tracks doesn't apply to bio's that don't have data. Skip calculating this to fix a NULL pointer access. Fixes: 2f6b2565d43cdb5 ("block: accumulate memory segment gaps per bio") Reported-by: Matthew Wilcox Signed-off-by: Keith Busch Reviewed-by: Yu Kuai Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe --- diff --git a/block/blk-merge.c b/block/blk-merge.c index 3ca6fbf8b7870..d3115d7469df0 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -737,6 +737,9 @@ u8 bio_seg_gap(struct request_queue *q, struct bio *prev, struct bio *next, { struct bio_vec pb, nb; + if (!bio_has_data(prev)) + return 0; + gaps_bit = min_not_zero(gaps_bit, prev->bi_bvec_gap_bit); gaps_bit = min_not_zero(gaps_bit, next->bi_bvec_gap_bit);