--- x/block/blk-map.c +++ y/block/blk-map.c @@ -269,6 +269,7 @@ static int bio_map_user_iov(struct reque unsigned int max_sectors = queue_max_hw_sectors(rq->q); unsigned int nr_vecs = iov_iter_npages(iter, BIO_MAX_VECS); struct bio *bio; + int add_pg = 0; int ret; int j; @@ -322,6 +323,7 @@ static int bio_map_user_iov(struct reque bio_release_page(bio, page); bytes -= n; offs = 0; + add_pg = 1; } } /* @@ -344,7 +346,8 @@ static int bio_map_user_iov(struct reque return 0; out_unmap: - bio_release_pages(bio, false); + if (add_pg) + bio_release_pages(bio, false); blk_mq_map_bio_put(bio); return ret; }