The number of bvecs can be obtained directly from struct request's nr_phys_segments field via blk_rq_nr_phys_segments(), so use that instead of iterating over the bvecs an extra time. Signed-off-by: Caleb Sander Mateos --- drivers/block/loop.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 13ce229d450c..8096478fad45 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -346,16 +346,13 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, struct request *rq = blk_mq_rq_from_pdu(cmd); struct bio *bio = rq->bio; struct file *file = lo->lo_backing_file; struct bio_vec tmp; unsigned int offset; - int nr_bvec = 0; + unsigned short nr_bvec = blk_rq_nr_phys_segments(rq); int ret; - rq_for_each_bvec(tmp, rq, rq_iter) - nr_bvec++; - if (rq->bio != rq->biotail) { bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_NOIO); if (!bvec) -- 2.45.2 The number of bvecs can be obtained directly from struct request's nr_phys_segments field via blk_rq_nr_phys_segments(), so use that instead of iterating over the bvecs an extra time. Signed-off-by: Caleb Sander Mateos --- drivers/block/zloop.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c index 92be9f0af00a..7883e56ed12a 100644 --- a/drivers/block/zloop.c +++ b/drivers/block/zloop.c @@ -368,11 +368,11 @@ static void zloop_rw(struct zloop_cmd *cmd) struct req_iterator rq_iter; struct zloop_zone *zone; struct iov_iter iter; struct bio_vec tmp; sector_t zone_end; - int nr_bvec = 0; + unsigned short nr_bvec = blk_rq_nr_phys_segments(rq); int ret; atomic_set(&cmd->ref, 2); cmd->sector = sector; cmd->nr_sectors = nr_sectors; @@ -435,13 +435,10 @@ static void zloop_rw(struct zloop_cmd *cmd) zone->wp += nr_sectors; if (zone->wp == zone_end) zone->cond = BLK_ZONE_COND_FULL; } - rq_for_each_bvec(tmp, rq, rq_iter) - nr_bvec++; - if (rq->bio != rq->biotail) { struct bio_vec *bvec; cmd->bvec = kmalloc_array(nr_bvec, sizeof(*cmd->bvec), GFP_NOIO); if (!cmd->bvec) { -- 2.45.2