From: Milan Broz <mbroz@redhat.com>

Move write error code following previous patch.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Milan Broz <mbroz@redhat.com>

---
 drivers/md/dm-crypt.c |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

Index: linux-2.6.23/drivers/md/dm-crypt.c
===================================================================
--- linux-2.6.23.orig/drivers/md/dm-crypt.c	2007-10-10 17:20:57.000000000 +0100
+++ linux-2.6.23/drivers/md/dm-crypt.c	2007-10-10 17:20:58.000000000 +0100
@@ -637,13 +637,21 @@ static void crypt_write_done(struct dm_c
 	struct bio *clone = io->ctx.bio_out;
 	struct crypt_config *cc = io->target->private;
 
-	/* crypt_convert should have filled the clone bio */
+	if (unlikely(io->ctx.err < 0)) {
+		crypt_free_buffer_pages(cc, clone, clone->bi_size);
+		bio_put(clone);
+		crypt_dec_pending(io, -EIO);
+		return;
+	}
 
+	/* crypt_convert should have filled the clone bio */
 	BUG_ON(io->ctx.idx_out < clone->bi_vcnt);
 
 	clone->bi_sector = cc->start + io->sector;
 	io->remaining -= clone->bi_size;
 	io->sector += bio_sectors(clone);
+
+	process_write_endio(io);
 }
 
 static void crypt_write_loop(struct dm_crypt_io *io)
@@ -668,16 +676,9 @@ static void crypt_write_loop(struct dm_c
 		io->ctx.idx_out = 0;
 
 		crypt_convert(cc, &io->ctx);
-		if (unlikely(io->ctx.err < 0)) {
-			crypt_free_buffer_pages(cc, clone, clone->bi_size);
-			bio_put(clone);
-			crypt_dec_pending(io, -EIO);
-			break;
-		}
-
 		crypt_write_done(io);
-
-		process_write_endio(io);
+		if (unlikely(io->ctx.err < 0))
+			break;
 	}
 
 	crypt_dec_pending(io, 0);
