summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgkostka <kostka.grzegorz@gmail.com>2015-10-27 20:56:04 +0100
committergkostka <kostka.grzegorz@gmail.com>2015-10-27 21:47:39 +0100
commit521bf29b9959334675c3019b81b3efc3ae39358e (patch)
treebe7af935b8d8d047713088265d13bf2a273220d6
parent6a7cf51891c3d0eba229765c98832ccd3fc9f3f5 (diff)
Introduce EXT4_CRC32_INIT instead of ~0
Using ~0 is potential dangerous in 8/16 bit architectures
-rw-r--r--lwext4/ext4_balloc.c3
-rw-r--r--lwext4/ext4_dir.c2
-rw-r--r--lwext4/ext4_dir_idx.c3
-rw-r--r--lwext4/ext4_extent.c3
-rw-r--r--lwext4/ext4_extent_full.c3
-rw-r--r--lwext4/ext4_fs.c6
-rw-r--r--lwext4/ext4_ialloc.c3
-rw-r--r--lwext4/ext4_super.c2
-rw-r--r--lwext4/ext4_types.h3
-rw-r--r--lwext4/ext4_xattr.c3
10 files changed, 21 insertions, 10 deletions
diff --git a/lwext4/ext4_balloc.c b/lwext4/ext4_balloc.c
index bad2be7..f7da851 100644
--- a/lwext4/ext4_balloc.c
+++ b/lwext4/ext4_balloc.c
@@ -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);
diff --git a/lwext4/ext4_dir.c b/lwext4/ext4_dir.c
index 9067586..a1b93f5 100644
--- a/lwext4/ext4_dir.c
+++ b/lwext4/ext4_dir.c
@@ -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,
diff --git a/lwext4/ext4_dir_idx.c b/lwext4/ext4_dir_idx.c
index d8e87c0..ac261a8 100644
--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -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,
diff --git a/lwext4/ext4_extent.c b/lwext4/ext4_extent.c
index 809fdec..d2a54e1 100644
--- a/lwext4/ext4_extent.c
+++ b/lwext4/ext4_extent.c
@@ -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,
diff --git a/lwext4/ext4_extent_full.c b/lwext4/ext4_extent_full.c
index e7dd00f..0dc6457 100644
--- a/lwext4/ext4_extent_full.c
+++ b/lwext4/ext4_extent_full.c
@@ -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,
diff --git a/lwext4/ext4_fs.c b/lwext4/ext4_fs.c
index 3b69817..8523b1c 100644
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -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,
diff --git a/lwext4/ext4_ialloc.c b/lwext4/ext4_ialloc.c
index df3e997..d941396 100644
--- a/lwext4/ext4_ialloc.c
+++ b/lwext4/ext4_ialloc.c
@@ -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);
diff --git a/lwext4/ext4_super.c b/lwext4/ext4_super.c
index f8145f7..65198c7 100644
--- a/lwext4/ext4_super.c
+++ b/lwext4/ext4_super.c
@@ -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));
}
diff --git a/lwext4/ext4_types.h b/lwext4/ext4_types.h
index 2cf1c50..3cbdbad 100644
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -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)
{
diff --git a/lwext4/ext4_xattr.c b/lwext4/ext4_xattr.c
index 4f26e8f..29bdebd 100644
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -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));