Commit 9a4c8019471386c6fb039ae9e30f5216b6b55a9e
Committed by
Theodore Ts'o
1 parent
939da10844
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
ext4: ensure Inode flags consistency are checked at build time
Flags being used by atomic operations in inode flags (e.g. ext4_test_inode_flag(), should be consistent with that actually stored in inodes, i.e.: EXT4_XXX_FL. It ensures that this consistency is checked at build-time, not at run-time. Currently, the flags consistency are being checked at run-time, but, there is no real reason to not do a build-time check instead of a run-time check. The code is comparing macro defined values with enum type variables, where both are constants, so, there is no problem in comparing constants at build-time. enum variables are treated as constants by the C compiler, according to the C99 specs (see www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf sec. 6.2.5, item 16), so, there is no real problem in comparing an enumeration type at build time Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Showing 2 changed files with 14 additions and 16 deletions Side-by-side Diff
fs/ext4/ext4.h
... | ... | @@ -463,25 +463,22 @@ |
463 | 463 | EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */ |
464 | 464 | }; |
465 | 465 | |
466 | -#define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) | |
467 | -#define CHECK_FLAG_VALUE(FLAG) if (!TEST_FLAG_VALUE(FLAG)) { \ | |
468 | - printk(KERN_EMERG "EXT4 flag fail: " #FLAG ": %d %d\n", \ | |
469 | - EXT4_##FLAG##_FL, EXT4_INODE_##FLAG); BUG_ON(1); } | |
470 | - | |
471 | 466 | /* |
472 | - * Since it's pretty easy to mix up bit numbers and hex values, and we | |
473 | - * can't do a compile-time test for ENUM values, we use a run-time | |
474 | - * test to make sure that EXT4_XXX_FL is consistent with respect to | |
475 | - * EXT4_INODE_XXX. If all is well the printk and BUG_ON will all drop | |
476 | - * out so it won't cost any extra space in the compiled kernel image. | |
477 | - * But it's important that these values are the same, since we are | |
478 | - * using EXT4_INODE_XXX to test for the flag values, but EXT4_XX_FL | |
479 | - * must be consistent with the values of FS_XXX_FL defined in | |
480 | - * include/linux/fs.h and the on-disk values found in ext2, ext3, and | |
481 | - * ext4 filesystems, and of course the values defined in e2fsprogs. | |
467 | + * Since it's pretty easy to mix up bit numbers and hex values, we use a | |
468 | + * build-time check to make sure that EXT4_XXX_FL is consistent with respect to | |
469 | + * EXT4_INODE_XXX. If all is well, the macros will be dropped, so, it won't cost | |
470 | + * any extra space in the compiled kernel image, otherwise, the build will fail. | |
471 | + * It's important that these values are the same, since we are using | |
472 | + * EXT4_INODE_XXX to test for flag values, but EXT4_XXX_FL must be consistent | |
473 | + * with the values of FS_XXX_FL defined in include/linux/fs.h and the on-disk | |
474 | + * values found in ext2, ext3 and ext4 filesystems, and of course the values | |
475 | + * defined in e2fsprogs. | |
482 | 476 | * |
483 | 477 | * It's not paranoia if the Murphy's Law really *is* out to get you. :-) |
484 | 478 | */ |
479 | +#define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG)) | |
480 | +#define CHECK_FLAG_VALUE(FLAG) BUILD_BUG_ON(!TEST_FLAG_VALUE(FLAG)) | |
481 | + | |
485 | 482 | static inline void ext4_check_flag_values(void) |
486 | 483 | { |
487 | 484 | CHECK_FLAG_VALUE(SECRM); |
fs/ext4/super.c