From 8abb2a5dbadab91f9cae22270054e9ee3b3a1d2f Mon Sep 17 00:00:00 2001
From: Kent Overstreet <koverstreet@google.com>
Date: Tue, 23 Apr 2013 21:51:48 -0700
Subject: bcache: Make sure blocksize isn't smaller than device blocksize

Sanity check to make sure we don't end up doing IO the device doesn't
support.

Signed-off-by: Kent Overstreet <koverstreet@google.com>
---
 drivers/md/bcache/super.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'drivers/md/bcache')

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 6817ea46cf0a..b3601476f7dd 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -139,13 +139,17 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
 	if (bch_is_zero(sb->uuid, 16))
 		goto err;
 
+	sb->block_size	= le16_to_cpu(s->block_size);
+
+	err = "Superblock block size smaller than device block size";
+	if (sb->block_size << 9 < bdev_logical_block_size(bdev))
+		goto err;
+
 	switch (sb->version) {
 	case BCACHE_SB_VERSION_BDEV:
-		sb->block_size	= le16_to_cpu(s->block_size);
 		sb->data_offset	= BDEV_DATA_START_DEFAULT;
 		break;
 	case BCACHE_SB_VERSION_BDEV_WITH_OFFSET:
-		sb->block_size	= le16_to_cpu(s->block_size);
 		sb->data_offset	= le64_to_cpu(s->data_offset);
 
 		err = "Bad data offset";
-- 
cgit v1.2.2