o Don't free incomplete pages in crypt_free_buffer_pages
o Make sure every encountered error gets seen.
o Fix hard to trigger bug in the read path where bi_next was not cleared.

[Christophe Saout]
--- diff/drivers/md/dm-crypt.c	2004-01-03 12:14:31.000000000 +0000
+++ source/drivers/md/dm-crypt.c	2004-01-03 12:14:36.000000000 +0000
@@ -282,7 +282,12 @@
 
 	while(bytes) {
 		struct bio_vec *bv = bio_iovec_idx(bio, i++);
+		if (bytes < bv->bv_len)
+			break;
+
+		BUG_ON(!bv->bv_page);
 		mempool_free(bv->bv_page, cc->page_pool);
+		bv->bv_page = NULL;
 		bytes -= bv->bv_len;
 	}
 }
@@ -295,15 +300,15 @@
 {
 	struct crypt_config *cc = (struct crypt_config *) io->target->private;
 
+	if (error < 0)
+		io->error = error;
+
 	if (!atomic_dec_and_test(&io->pending))
 		return;
 
 	if (io->first_clone)
 		bio_put(io->first_clone);
 
-	if (error < 0)
-		io->error = error;
-
 	if (io->bio)
 		bio_endio(io->bio, io->bio->bi_size, io->error);
 
@@ -346,6 +351,7 @@
 {
 	unsigned long flags;
 
+	bio->bi_next = NULL;
 	spin_lock_irqsave(&_kcryptd_lock, flags);
 	if (_kcryptd_bio_tail)
 		_kcryptd_bio_tail->bi_next = bio;
