From: Jun'ichi Nomura Date: Thu, 12 Jul 2007 16:27:45 +0000 (+0100) Subject: dm io: fix panic on large request X-Git-Tag: v2.6.23-rc1~1095 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=596f138eede0c113aa655937c8be85fc15ccd61c;p=linux-2.6 dm io: fix panic on large request bio_alloc_bioset() will return NULL if 'num_vecs' is too large. Use bio_get_nr_vecs() to get estimation of maximum number. Cc: stable@kernel.org Signed-off-by: "Jun'ichi Nomura" Signed-off-by: Alasdair G Kergon Signed-off-by: Linus Torvalds --- diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c index 352c6fbeac..f3a7724864 100644 --- a/drivers/md/dm-io.c +++ b/drivers/md/dm-io.c @@ -293,7 +293,10 @@ static void do_region(int rw, unsigned int region, struct io_region *where, * bvec for bio_get/set_region() and decrement bi_max_vecs * to hide it from bio_add_page(). */ - num_bvecs = (remaining / (PAGE_SIZE >> SECTOR_SHIFT)) + 2; + num_bvecs = dm_sector_div_up(remaining, + (PAGE_SIZE >> SECTOR_SHIFT)); + num_bvecs = 1 + min_t(int, bio_get_nr_vecs(where->bdev), + num_bvecs); bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios); bio->bi_sector = where->sector + (where->count - remaining); bio->bi_bdev = where->bdev;