From: Alasdair G Kergon <agk@redhat.com>

Make the caller reponsible for incrementing the pending count before calling
kcryptd_crypt_write_io_submit() in the non-async case to bring it into line
with the async case.

Signed-off-by: Alasdair G Kergon <agk@redhat.com>
---
 drivers/md/dm-crypt.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Index: linux-2.6.27/drivers/md/dm-crypt.c
===================================================================
--- linux-2.6.27.orig/drivers/md/dm-crypt.c	2008-10-10 12:21:31.000000000 +0100
+++ linux-2.6.27/drivers/md/dm-crypt.c	2008-10-10 12:21:32.000000000 +0100
@@ -685,10 +685,8 @@ static void kcryptd_crypt_write_io_submi
 
 	if (async)
 		kcryptd_queue_io(io);
-	else {
-		crypt_inc_pending(io);
+	else
 		generic_make_request(clone);
-	}
 }
 
 static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
@@ -724,9 +722,12 @@ static void kcryptd_crypt_write_convert(
 
 		if (atomic_dec_and_test(&io->ctx.pending)) {
 			/* processed, no running async crypto  */
+			crypt_inc_pending(io);
 			kcryptd_crypt_write_io_submit(io, r, 0);
-			if (unlikely(r < 0))
+			if (unlikely(r < 0)) {
+				crypt_dec_pending(io);
 				break;
+			}
 		} else
 			crypt_inc_pending(io);
 
