diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c index 8bdc8a87b249c4b9a0b46ab0e22308e30ed7c1d6..4d19c45158b45a695c31cc31415a15a8fb02c30e 100644 --- a/drivers/md/dm-io.c +++ b/drivers/md/dm-io.c @@ -126,7 +126,8 @@ static void dec_count(struct io *io, unsigned int region, int error) static int endio(struct bio *bio, unsigned int done, int error) { - struct io *io = (struct io *) bio->bi_private; + struct io *io; + unsigned region; /* keep going until we've finished */ if (bio->bi_size) @@ -135,10 +136,17 @@ static int endio(struct bio *bio, unsigned int done, int error) if (error && bio_data_dir(bio) == READ) zero_fill_bio(bio); - dec_count(io, bio_get_region(bio), error); + /* + * The bio destructor in bio_put() may use the io object. + */ + io = bio->bi_private; + region = bio_get_region(bio); + bio->bi_max_vecs++; bio_put(bio); + dec_count(io, region, error); + return 0; }