Skip to content

Commit

Permalink
bcache: Make sure blocksize isn't smaller than device blocksize
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kent Overstreet committed Apr 24, 2013
1 parent a09ded8 commit 8abb2a5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/md/bcache/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 8abb2a5

Please sign in to comment.