Add a helper to check if we have a valid csum type from the super block.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 cmds/inspect-dump-super.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/cmds/inspect-dump-super.c b/cmds/inspect-dump-super.c
index 58bf82b0bbd3..272df1bfdc14 100644
--- a/cmds/inspect-dump-super.c
+++ b/cmds/inspect-dump-super.c
@@ -311,6 +311,16 @@ static void print_readable_super_flag(u64 flag)
                                     super_flags_num, BTRFS_SUPER_FLAG_SUPP);
 }
 
+static bool is_valid_csum_type(u16 csum_type)
+{
+       switch (csum_type) {
+       case BTRFS_CSUM_TYPE_CRC32:
+               return true;
+       default:
+               return false;
+       }
+}
+
 static void dump_superblock(struct btrfs_super_block *sb, int full)
 {
        int i;
@@ -326,7 +336,7 @@ static void dump_superblock(struct btrfs_super_block *sb, 
int full)
        csum_type = btrfs_super_csum_type(sb);
        csum_size = BTRFS_CSUM_SIZE;
        printf("csum_type\t\t%hu (", csum_type);
-       if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
+       if (!is_valid_csum_type(csum_type)) {
                printf("INVALID");
        } else {
                if (csum_type == BTRFS_CSUM_TYPE_CRC32) {
@@ -342,8 +352,7 @@ static void dump_superblock(struct btrfs_super_block *sb, 
int full)
        printf("csum\t\t\t0x");
        for (i = 0, p = sb->csum; i < csum_size; i++)
                printf("%02x", p[i]);
-       if (csum_type != BTRFS_CSUM_TYPE_CRC32 ||
-           csum_size != btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32])
+       if (!is_valid_csum_type(csum_type))
                printf(" [UNKNOWN CSUM TYPE OR SIZE]");
        else if (check_csum_sblock(sb, csum_size, csum_type))
                printf(" [match]");
-- 
2.16.4

Reply via email to