From: Mikulas Patocka <[email-masked]>

Some callers assume they can always add at least one page to an empty bio,
so dm_merge_bvec should not return 0 in this case: we'll reject the I/O
later after the bio is submitted.

Signed-off-by: Mikulas Patocka <[email-masked]>
Signed-off-by: Alasdair G Kergon <[email-masked]>
---
 drivers/md/dm.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Index: linux-2.6.27-rc7/drivers/md/dm.c
===================================================================
--- linux-2.6.27-rc7.orig/drivers/md/dm.c	2008-10-01 12:07:46.000000000 +0100
+++ linux-2.6.27-rc7/drivers/md/dm.c	2008-10-01 13:04:10.000000000 +0100
@@ -837,10 +837,10 @@ static int dm_merge_bvec(struct request_
 	struct dm_table *map = dm_get_table(md);
 	struct dm_target *ti;
 	sector_t max_sectors;
-	int max_size;
+	int max_size = 0;
 
 	if (unlikely(!map))
-		return 0;
+		goto out;
 
 	ti = dm_table_find_target(map, bvm->bi_sector);
 
@@ -861,14 +861,15 @@ static int dm_merge_bvec(struct request_
 	if (max_size && ti->type->merge)
 		max_size = ti->type->merge(ti, bvm, biovec, max_size);
 
+	dm_table_put(map);
+
+out:
 	/*
 	 * Always allow an entire first page
 	 */
 	if (max_size <= biovec->bv_len && !(bvm->bi_size >> SECTOR_SHIFT))
 		max_size = biovec->bv_len;
 
-	dm_table_put(map);
-
 	return max_size;
 }