fix bug in add-support-collapse-range
[ext4-patch-queue.git] / ext4-dont-calculate-total-xattr-size-if-unneeded
blobd69ef9780811f8cd6c36f94302ff3d005af54816
1 ext4: don't calculate total xattr header size unless needed
3 The function ext4_expand_extra_isize_ea() doesn't need the size of all
4 of the extended attribute headers.  So if we don't calculate it when
5 it is unneeded, it we can skip some undeeded memory references, and as
6 a bonus, we eliminate some kvetching by static code analysis tools.
8 Addresses-Coverity-Id: #741291
10 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
11 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
12 index e175e94..185066f 100644
13 --- a/fs/ext4/xattr.c
14 +++ b/fs/ext4/xattr.c
15 @@ -567,12 +567,13 @@ static size_t ext4_xattr_free_space(struct ext4_xattr_entry *last,
16                                     size_t *min_offs, void *base, int *total)
17  {
18         for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
19 -               *total += EXT4_XATTR_LEN(last->e_name_len);
20                 if (!last->e_value_block && last->e_value_size) {
21                         size_t offs = le16_to_cpu(last->e_value_offs);
22                         if (offs < *min_offs)
23                                 *min_offs = offs;
24                 }
25 +               if (total)
26 +                       *total += EXT4_XATTR_LEN(last->e_name_len);
27         }
28         return (*min_offs - ((void *)last - base) - sizeof(__u32));
29  }
30 @@ -1228,7 +1229,7 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
31         struct ext4_xattr_block_find *bs = NULL;
32         char *buffer = NULL, *b_entry_name = NULL;
33         size_t min_offs, free;
34 -       int total_ino, total_blk;
35 +       int total_ino;
36         void *base, *start, *end;
37         int extra_isize = 0, error = 0, tried_min_extra_isize = 0;
38         int s_min_extra_isize = le16_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_min_extra_isize);
39 @@ -1286,8 +1287,7 @@ retry:
40                 first = BFIRST(bh);
41                 end = bh->b_data + bh->b_size;
42                 min_offs = end - base;
43 -               free = ext4_xattr_free_space(first, &min_offs, base,
44 -                                            &total_blk);
45 +               free = ext4_xattr_free_space(first, &min_offs, base, NULL);
46                 if (free < new_extra_isize) {
47                         if (!tried_min_extra_isize && s_min_extra_isize) {
48                                 tried_min_extra_isize++;