From a45f0c854fb38b616717c4fed55b5a4f5dff65f2 Mon Sep 17 00:00:00 2001 From: Kozlowski Mateusz Date: Thu, 8 Apr 2021 12:28:35 +0200 Subject: [PATCH] Fix _blockdev_set_bio_data iteration The data->size field can be initialized to a lower value than bio->bi_vcnt, if the bio is split. The bio_for_each_segment then iterates based on the original indexes and the mismatch eventually causes a BUG_ON. Fixes #714 Signed-off-by: Kozlowski Mateusz --- modules/cas_cache/volume/vol_block_dev_top.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/cas_cache/volume/vol_block_dev_top.c b/modules/cas_cache/volume/vol_block_dev_top.c index dc0a272..952f29a 100644 --- a/modules/cas_cache/volume/vol_block_dev_top.c +++ b/modules/cas_cache/volume/vol_block_dev_top.c @@ -38,11 +38,12 @@ static void _blockdev_set_bio_data(struct blk_data *data, struct bio *bio) { #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) struct bio_vec *bvec; - uint32_t i = 0; + uint32_t iter = 0, i = 0; - bio_for_each_segment(bvec, bio, i) { + bio_for_each_segment(bvec, bio, iter) { BUG_ON(i >= data->size); data->vec[i] = *bvec; + i++; } #else struct bio_vec bvec;