diff options
author | Theodore Ts'o <tytso@mit.edu> | 2014-02-19 20:15:21 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2014-02-19 20:15:21 -0500 |
commit | 7b1b2c1b9c397dcb86293ae79aa7fb7c5446120f (patch) | |
tree | bc988ef69f77ffc55c94a88ae3f5f1a0f78df053 | |
parent | 9a6633b1a3603ccdffec669033616f9ebb35a988 (diff) |
ext4: don't calculate total xattr header size unless needed
The function ext4_expand_extra_isize_ea() doesn't need the size of all
of the extended attribute headers. So if we don't calculate it when
it is unneeded, it we can skip some undeeded memory references, and as
a bonus, we eliminate some kvetching by static code analysis tools.
Addresses-Coverity-Id: #741291
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r-- | fs/ext4/xattr.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index e175e94116ac..185066f475f1 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c | |||
@@ -567,12 +567,13 @@ static size_t ext4_xattr_free_space(struct ext4_xattr_entry *last, | |||
567 | size_t *min_offs, void *base, int *total) | 567 | size_t *min_offs, void *base, int *total) |
568 | { | 568 | { |
569 | for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) { | 569 | for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) { |
570 | *total += EXT4_XATTR_LEN(last->e_name_len); | ||
571 | if (!last->e_value_block && last->e_value_size) { | 570 | if (!last->e_value_block && last->e_value_size) { |
572 | size_t offs = le16_to_cpu(last->e_value_offs); | 571 | size_t offs = le16_to_cpu(last->e_value_offs); |
573 | if (offs < *min_offs) | 572 | if (offs < *min_offs) |
574 | *min_offs = offs; | 573 | *min_offs = offs; |
575 | } | 574 | } |
575 | if (total) | ||
576 | *total += EXT4_XATTR_LEN(last->e_name_len); | ||
576 | } | 577 | } |
577 | return (*min_offs - ((void *)last - base) - sizeof(__u32)); | 578 | return (*min_offs - ((void *)last - base) - sizeof(__u32)); |
578 | } | 579 | } |
@@ -1228,7 +1229,7 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize, | |||
1228 | struct ext4_xattr_block_find *bs = NULL; | 1229 | struct ext4_xattr_block_find *bs = NULL; |
1229 | char *buffer = NULL, *b_entry_name = NULL; | 1230 | char *buffer = NULL, *b_entry_name = NULL; |
1230 | size_t min_offs, free; | 1231 | size_t min_offs, free; |
1231 | int total_ino, total_blk; | 1232 | int total_ino; |
1232 | void *base, *start, *end; | 1233 | void *base, *start, *end; |
1233 | int extra_isize = 0, error = 0, tried_min_extra_isize = 0; | 1234 | int extra_isize = 0, error = 0, tried_min_extra_isize = 0; |
1234 | int s_min_extra_isize = le16_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_min_extra_isize); | 1235 | int s_min_extra_isize = le16_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_min_extra_isize); |
@@ -1286,8 +1287,7 @@ retry: | |||
1286 | first = BFIRST(bh); | 1287 | first = BFIRST(bh); |
1287 | end = bh->b_data + bh->b_size; | 1288 | end = bh->b_data + bh->b_size; |
1288 | min_offs = end - base; | 1289 | min_offs = end - base; |
1289 | free = ext4_xattr_free_space(first, &min_offs, base, | 1290 | free = ext4_xattr_free_space(first, &min_offs, base, NULL); |
1290 | &total_blk); | ||
1291 | if (free < new_extra_isize) { | 1291 | if (free < new_extra_isize) { |
1292 | if (!tried_min_extra_isize && s_min_extra_isize) { | 1292 | if (!tried_min_extra_isize && s_min_extra_isize) { |
1293 | tried_min_extra_isize++; | 1293 | tried_min_extra_isize++; |