Introduce EXT4_CRC32_INIT instead of ~0
authorgkostka <kostka.grzegorz@gmail.com>
Tue, 27 Oct 2015 19:56:04 +0000 (20:56 +0100)
committergkostka <kostka.grzegorz@gmail.com>
Tue, 27 Oct 2015 20:47:39 +0000 (21:47 +0100)
Using ~0 is potential dangerous in 8/16 bit architectures

lwext4/ext4_balloc.c
lwext4/ext4_dir.c
lwext4/ext4_dir_idx.c
lwext4/ext4_extent.c
lwext4/ext4_extent_full.c
lwext4/ext4_fs.c
lwext4/ext4_ialloc.c
lwext4/ext4_super.c
lwext4/ext4_types.h
lwext4/ext4_xattr.c

index bad2be7521e2e8b215ba50b9c187a543df77a00d..f7da851e8e6c1191252157114085d4974156b0ca 100644 (file)
@@ -87,7 +87,8 @@ static uint32_t ext4_balloc_bitmap_csum(struct ext4_sblock *sb,
                        ext4_get32(sb, blocks_per_group);
 
                /* First calculate crc32 checksum against fs uuid */
-               checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+               checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
+                               sizeof(sb->uuid));
                /* Then calculate crc32 checksum against block_group_desc */
                checksum = ext4_crc32c(checksum, bitmap,
                                     blocks_per_group / 8);
index 90675866bb11f98a49832b248a384f970e0af847..a1b93f5b8237b1e0b5c7e3eb74be6cd0dca8ee9c 100644 (file)
@@ -79,7 +79,7 @@ static uint32_t ext4_dir_checksum(struct ext4_inode_ref *inode_ref,
                to_le32(ext4_inode_get_generation(inode_ref->inode));
 
        /* First calculate crc32 checksum against fs uuid */
-       checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+       checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid, sizeof(sb->uuid));
        /* Then calculate crc32 checksum against inode number
         * and inode generation */
        checksum = ext4_crc32c(checksum, &ino_index,
index d8e87c02ebfdd4fe185dae71c244a0791c95a21d..ac261a8bfbeed84d7c42c100aac0f912ace0038d 100644 (file)
@@ -224,7 +224,8 @@ ext4_dir_dx_checksum(struct ext4_inode_ref *inode_ref,
                orig_checksum = t->checksum;
                t->checksum = 0;
                /* First calculate crc32 checksum against fs uuid */
-               checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+               checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
+                               sizeof(sb->uuid));
                /* Then calculate crc32 checksum against inode number
                 * and inode generation */
                checksum = ext4_crc32c(checksum, &ino_index,
index 809fdec0e440d14dec5f6536cfe7848ce925ab05..d2a54e1f31d3a36e49c96e7cce2d2658a9407d7e 100644 (file)
@@ -136,7 +136,8 @@ static uint32_t ext4_ext_block_csum(struct ext4_inode_ref *inode_ref,
                uint32_t ino_gen =
                        to_le32(ext4_inode_get_generation(inode_ref->inode));
                /* First calculate crc32 checksum against fs uuid */
-               checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+               checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
+                               sizeof(sb->uuid));
                /* Then calculate crc32 checksum against inode number
                 * and inode generation */
                checksum = ext4_crc32c(checksum, &ino_index,
index e7dd00f8d84c0cfa656a5847fc6ceb4d97395df0..0dc645757940df90581f1fa67aa09a331c4a2ed6 100644 (file)
@@ -320,7 +320,8 @@ static uint32_t ext4_ext_block_csum(struct ext4_inode_ref *inode_ref,
                uint32_t ino_gen =
                        to_le32(ext4_inode_get_generation(inode_ref->inode));
                /* First calculate crc32 checksum against fs uuid */
-               checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+               checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
+                               sizeof(sb->uuid));
                /* Then calculate crc32 checksum against inode number
                 * and inode generation */
                checksum = ext4_crc32c(checksum, &ino_index,
index 3b69817c34115c3fbe790e668f9abe6a981d849b..8523b1cfbf0e1aa109d3243c4ab6795e469f4e91 100644 (file)
@@ -582,7 +582,8 @@ static uint16_t ext4_fs_bg_checksum(struct ext4_sblock *sb, uint32_t bgid,
                bg->checksum = 0;
 
                /* First calculate crc32 checksum against fs uuid */
-               checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+               checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
+                               sizeof(sb->uuid));
                /* Then calculate crc32 checksum against bgid */
                checksum = ext4_crc32c(checksum, &le32_bgid,
                                     sizeof(bgid));
@@ -661,7 +662,8 @@ static uint32_t ext4_fs_inode_checksum(struct ext4_inode_ref *inode_ref)
                ext4_inode_set_checksum(sb, inode_ref->inode, 0);
 
                /* First calculate crc32 checksum against fs uuid */
-               checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+               checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
+                               sizeof(sb->uuid));
                /* Then calculate crc32 checksum against inode number
                 * and inode generation */
                checksum = ext4_crc32c(checksum, &ino_index,
index df3e997e6c133b6f8b11e25bb982ab575cf74cdb..d941396d37463a16cd0642660b7a572724326b6a 100644 (file)
@@ -95,7 +95,8 @@ static uint32_t ext4_ialloc_bitmap_csum(struct ext4_sblock *sb,
                        ext4_get32(sb, inodes_per_group);
 
                /* First calculate crc32 checksum against fs uuid */
-               checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+               checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
+                               sizeof(sb->uuid));
                /* Then calculate crc32 checksum against inode bitmap */
                checksum = ext4_crc32c(checksum, bitmap,
                                     (inodes_per_group + 7) / 8);
index f8145f7b0cdf578d5ac269b20a5472bc884f5e8a..65198c7462e9d7a04da3c254585ed524bb773310 100644 (file)
@@ -82,7 +82,7 @@ uint32_t ext4_inodes_in_group_cnt(struct ext4_sblock *s, uint32_t bgid)
 
 static uint32_t ext4_sb_csum(struct ext4_sblock *s)
 {
-       return ext4_crc32c(~0, s,
+       return ext4_crc32c(EXT4_CRC32_INIT, s,
                        offsetof(struct ext4_sblock, checksum));
 }
 
index 2cf1c503be658da3e18f5a67d5fe38f416c61517..3cbdbadf1ecccf05f8d9a5eec7b62decad762443 100644 (file)
@@ -889,6 +889,9 @@ struct ext4_xattr_ref {
 
 /*****************************************************************************/
 
+#define EXT4_CRC32_INIT (0xFFFFFFFFUL)
+
+/*****************************************************************************/
 #ifdef CONFIG_BIG_ENDIAN
 static inline uint64_t to_le64(uint64_t n)
 {
index 4f26e8fb916ffee89df287d072b1d6bb615ffb64..29bdebd1f5cd1fb2b6812378983941131124e0a3 100644 (file)
@@ -128,7 +128,8 @@ ext4_xattr_block_checksum(struct ext4_inode_ref *inode_ref,
                orig_checksum = header->h_checksum;
                header->h_checksum = 0;
                /* First calculate crc32 checksum against fs uuid */
-               checksum = ext4_crc32c(~0, sb->uuid, sizeof(sb->uuid));
+               checksum = ext4_crc32c(EXT4_CRC32_INIT, sb->uuid,
+                               sizeof(sb->uuid));
                /* Then calculate crc32 checksum block number */
                checksum = ext4_crc32c(checksum, &le64_blocknr,
                                     sizeof(le64_blocknr));