diff options
author | Coly Li <colyli@suse.de> | 2020-07-25 14:00:24 +0200 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2020-07-25 15:38:20 +0200 |
commit | c557a5f7bb2558f1386038549c289d7a20c78730 (patch) | |
tree | 03268fe1ee770a5ca23884133de5a6cdb3940a06 /drivers/md/bcache | |
parent | bcache: add read_super_common() to read major part of super block (diff) | |
download | linux-c557a5f7bb2558f1386038549c289d7a20c78730.tar.xz linux-c557a5f7bb2558f1386038549c289d7a20c78730.zip |
bcache: add more accurate error information in read_super_common()
The improperly set bucket or block size will trigger error in
read_super_common(). For large bucket size, a more accurate error message
for invalid bucket or block size is necessary.
This patch disassembles the combined if() checks into multiple single
if() check, and provide more accurate error message for each check
failure condition.
Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/md/bcache')
-rw-r--r-- | drivers/md/bcache/super.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index a234c4c9c89b..8c4b61f50517 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -79,11 +79,20 @@ static const char *read_super_common(struct cache_sb *sb, struct block_device * if (sb->nbuckets < 1 << 7) goto err; - err = "Bad block/bucket size"; - if (!is_power_of_2(sb->block_size) || - sb->block_size > PAGE_SECTORS || - !is_power_of_2(sb->bucket_size) || - sb->bucket_size < PAGE_SECTORS) + err = "Bad block size (not power of 2)"; + if (!is_power_of_2(sb->block_size)) + goto err; + + err = "Bad block size (larger than page size)"; + if (sb->block_size > PAGE_SECTORS) + goto err; + + err = "Bad bucket size (not power of 2)"; + if (!is_power_of_2(sb->bucket_size)) + goto err; + + err = "Bad bucket size (smaller than page size)"; + if (sb->bucket_size < PAGE_SECTORS) goto err; err = "Invalid superblock: device too small"; |