From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aserp2120.oracle.com ([141.146.126.78]:60242 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751755AbeCTXbd (ORCPT ); Tue, 20 Mar 2018 19:31:33 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2KNNwxZ086298 for ; Tue, 20 Mar 2018 23:31:32 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2gubxc80ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Mar 2018 23:31:31 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w2KNVUdE025492 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Mar 2018 23:31:31 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2KNVUeG017733 for ; Tue, 20 Mar 2018 23:31:30 GMT From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 1/2] btrfs: cleanup btrfs_check_super_csum() to check the csum_type to the type Date: Wed, 21 Mar 2018 07:33:15 +0800 Message-Id: <20180320233316.20653-2-anand.jain@oracle.com> In-Reply-To: <20180320233316.20653-1-anand.jain@oracle.com> Sender: linux-btrfs-owner@vger.kernel.org List-ID: References: <20180320233316.20653-1-anand.jain@oracle.com> %csum_type is being checked to check the number of csum types we support, which is 1 as of now. Instead just check if the type matches with the only type we support, that is BTRFS_CSUM_TYPE_CRC32. And further adds cleanup. Signed-off-by: Anand Jain --- fs/btrfs/disk-io.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 1657d6aa4fa6..582ed6af3c50 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -399,32 +399,29 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, struct btrfs_super_block *disk_sb = (struct btrfs_super_block *)raw_disk_sb; u16 csum_type = btrfs_super_csum_type(disk_sb); - int ret = 0; - - if (csum_type == BTRFS_CSUM_TYPE_CRC32) { - u32 crc = ~(u32)0; - char result[sizeof(crc)]; - - /* - * The super_block structure does not span the whole - * BTRFS_SUPER_INFO_SIZE range, we expect that the unused space - * is filled with zeros and is included in the checksum. - */ - crc = btrfs_csum_data(raw_disk_sb + BTRFS_CSUM_SIZE, - crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE); - btrfs_csum_final(crc, result); - - if (memcmp(raw_disk_sb, result, sizeof(result))) - ret = 1; - } + u32 crc = ~(u32)0; + char result[sizeof(crc)]; - if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) { + /* We support csum type crc32 only as of now */ + if (csum_type != BTRFS_CSUM_TYPE_CRC32) { btrfs_err(fs_info, "unsupported checksum algorithm %u", - csum_type); - ret = 1; + csum_type); + return 1; } - return ret; + /* + * The super_block structure does not span the whole + * BTRFS_SUPER_INFO_SIZE range, we expect that the unused space + * is filled with zeros and is included in the checksum. + */ + crc = btrfs_csum_data(raw_disk_sb + BTRFS_CSUM_SIZE, + crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE); + btrfs_csum_final(crc, result); + + if (memcmp(raw_disk_sb, result, sizeof(result))) + return 1; + + return 0; } /* -- 2.15.0