add patch jbd2_log_wait_for_space-improve-error-detection
[ext4-patch-queue.git] / call-ext4_ext_drop_refs-from-ext4_ext_find_extent
blobb63d16de71d129221fdeaf1901982f889ecf3ad3
1 ext4: call ext4_ext_drop_refs() from ext4_ext_find_extent()
3 In nearly all of the calls to ext4_ext_find_extent() where the caller
4 is trying to recycle the path object, ext4_ext_drop_refs() gets called
5 to release the buffer heads before the path object gets overwritten.
6 To simplify things for the callers, and to avoid the possibility of a
7 memory leak, make ext4_ext_find_extent() responsible for dropping the
8 buffers.
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 ---
12  fs/ext4/extents.c | 11 ++++-------
13  1 file changed, 4 insertions(+), 7 deletions(-)
15 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
16 index f6d8b00..62aa508 100644
17 --- a/fs/ext4/extents.c
18 +++ b/fs/ext4/extents.c
19 @@ -859,8 +859,10 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
20         eh = ext_inode_hdr(inode);
21         depth = ext_depth(inode);
23 -       /* account possible depth increase */
24 -       if (!path) {
25 +       if (path)
26 +               ext4_ext_drop_refs(path);
27 +       else {
28 +               /* account possible depth increase */
29                 path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 2),
30                                 GFP_NOFS);
31                 if (unlikely(!path))
32 @@ -1348,7 +1350,6 @@ repeat:
33                         goto out;
35                 /* refill path */
36 -               ext4_ext_drop_refs(path);
37                 path = ext4_ext_find_extent(inode,
38                                     (ext4_lblk_t)le32_to_cpu(newext->ee_block),
39                                     ppath, gb_flags);
40 @@ -1361,7 +1362,6 @@ repeat:
41                         goto out;
43                 /* refill path */
44 -               ext4_ext_drop_refs(path);
45                 path = ext4_ext_find_extent(inode,
46                                    (ext4_lblk_t)le32_to_cpu(newext->ee_block),
47                                     ppath, gb_flags);
48 @@ -3325,7 +3325,6 @@ static int ext4_split_extent(handle_t *handle,
49          * Update path is required because previous ext4_split_extent_at() may
50          * result in split of original leaf or extent zeroout.
51          */
52 -       ext4_ext_drop_refs(path);
53         path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
54         if (IS_ERR(path))
55                 return PTR_ERR(path);
56 @@ -3724,7 +3723,6 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle,
57                                                  EXT4_GET_BLOCKS_CONVERT);
58                 if (err < 0)
59                         return err;
60 -               ext4_ext_drop_refs(path);
61                 path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
62                 if (IS_ERR(path))
63                         return PTR_ERR(path);
64 @@ -3953,7 +3951,6 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
65                                 EXT4_GET_BLOCKS_CONVERT_UNWRITTEN);
66                 if (err < 0)
67                         return err;
68 -               ext4_ext_drop_refs(path);
69                 path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
70                 if (IS_ERR(path))
71                         return PTR_ERR(path);