Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: don't initialize bi_vcnt for cloned bio in bio_iov_bvec_set()

bio_iov_bvec_set() creates a cloned bio that borrows a bvec array from
an iov_iter. For cloned bios, bi_vcnt is meaningless because iteration
is controlled entirely by bi_iter (bi_idx, bi_size, bi_bvec_done), not
by bi_vcnt. Remove the incorrect bi_vcnt assignment.

Explicitly initialize bi_iter.bi_idx to 0 to ensure iteration starts
at the first bvec. While bi_idx is typically already zero from bio
initialization, making this explicit improves clarity and correctness.

This change also avoids accessing iter->nr_segs, which is an iov_iter
implementation detail that block code should not depend on.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Ming Lei and committed by
Jens Axboe
64186431 ee623c89

+1 -1
+1 -1
block/bio.c
··· 1165 1165 { 1166 1166 WARN_ON_ONCE(bio->bi_max_vecs); 1167 1167 1168 - bio->bi_vcnt = iter->nr_segs; 1169 1168 bio->bi_io_vec = (struct bio_vec *)iter->bvec; 1169 + bio->bi_iter.bi_idx = 0; 1170 1170 bio->bi_iter.bi_bvec_done = iter->iov_offset; 1171 1171 bio->bi_iter.bi_size = iov_iter_count(iter); 1172 1172 bio_set_flag(bio, BIO_CLONED);