Commit 707d1a2f authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: optimize __ext4_check_dir_entry()

Make __ext4_check_dir_entry() a bit easier to understand, and reduce
the object size of the function by over 11%.
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Link: https://lore.kernel.org/r/20191209004346.38526-1-tytso@mit.eduSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 109ba779
...@@ -72,6 +72,7 @@ int __ext4_check_dir_entry(const char *function, unsigned int line, ...@@ -72,6 +72,7 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
const char *error_msg = NULL; const char *error_msg = NULL;
const int rlen = ext4_rec_len_from_disk(de->rec_len, const int rlen = ext4_rec_len_from_disk(de->rec_len,
dir->i_sb->s_blocksize); dir->i_sb->s_blocksize);
const int next_offset = ((char *) de - buf) + rlen;
if (unlikely(rlen < EXT4_DIR_REC_LEN(1))) if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
error_msg = "rec_len is smaller than minimal"; error_msg = "rec_len is smaller than minimal";
...@@ -79,13 +80,11 @@ int __ext4_check_dir_entry(const char *function, unsigned int line, ...@@ -79,13 +80,11 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
error_msg = "rec_len % 4 != 0"; error_msg = "rec_len % 4 != 0";
else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len))) else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
error_msg = "rec_len is too small for name_len"; error_msg = "rec_len is too small for name_len";
else if (unlikely(((char *) de - buf) + rlen > size)) else if (unlikely(next_offset > size))
error_msg = "directory entry overrun"; error_msg = "directory entry overrun";
else if (unlikely(((char *) de - buf) + rlen > else if (unlikely(next_offset > size - EXT4_DIR_REC_LEN(1) &&
size - EXT4_DIR_REC_LEN(1) && next_offset != size))
((char *) de - buf) + rlen != size)) {
error_msg = "directory entry too close to block end"; error_msg = "directory entry too close to block end";
}
else if (unlikely(le32_to_cpu(de->inode) > else if (unlikely(le32_to_cpu(de->inode) >
le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count))) le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count)))
error_msg = "inode out of bounds"; error_msg = "inode out of bounds";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment