shithub: lwext4

Download patch

ref: 521bf29b9959334675c3019b81b3efc3ae39358e
parent: 6a7cf51891c3d0eba229765c98832ccd3fc9f3f5
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Oct 27 16:56:04 EDT 2015

Introduce EXT4_CRC32_INIT instead of ~0

Using ~0 is potential dangerous in 8/16 bit architectures

--- a/lwext4/ext4_balloc.c
+++ b/lwext4/ext4_balloc.c
@@ -87,7 +87,8 @@
 			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);
--- a/lwext4/ext4_dir.c
+++ b/lwext4/ext4_dir.c
@@ -79,7 +79,7 @@
 		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,
--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -224,7 +224,8 @@
 		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,
--- a/lwext4/ext4_extent.c
+++ b/lwext4/ext4_extent.c
@@ -136,7 +136,8 @@
 		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,
--- a/lwext4/ext4_extent_full.c
+++ b/lwext4/ext4_extent_full.c
@@ -320,7 +320,8 @@
 		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,
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -582,7 +582,8 @@
 		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 @@
 		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,
--- a/lwext4/ext4_ialloc.c
+++ b/lwext4/ext4_ialloc.c
@@ -95,7 +95,8 @@
 			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);
--- a/lwext4/ext4_super.c
+++ b/lwext4/ext4_super.c
@@ -82,7 +82,7 @@
 
 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));
 }
 
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -889,6 +889,9 @@
 
 /*****************************************************************************/
 
+#define EXT4_CRC32_INIT (0xFFFFFFFFUL)
+
+/*****************************************************************************/
 #ifdef CONFIG_BIG_ENDIAN
 static inline uint64_t to_le64(uint64_t n)
 {
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -128,7 +128,8 @@
 		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));