add patch move-error-report-out-of-atomic-context
[ext4-patch-queue.git] / make-ext4_ext_drop_refs-allow-NULL-arguments
blob25a3e3f57b16968daa9df5aec9e16f8576360c3c
1 ext4: allow a NULL argument to ext4_ext_drop_refs()
3 Teach ext4_ext_drop_refs() to accept a NULL argument, much like
4 kfree().  This allows us to drop a lot of checks to make sure path is
5 non-NULL before calling ext4_ext_drop_refs().
7 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 ---
9  fs/ext4/extents.c        | 48 ++++++++++++++++++------------------------------
10  fs/ext4/extents_status.c |  6 ++----
11  fs/ext4/migrate.c        |  6 ++----
12  fs/ext4/move_extent.c    | 20 +++++++-------------
13  4 files changed, 29 insertions(+), 51 deletions(-)
15 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
16 index 62aa508..17a1f6f 100644
17 --- a/fs/ext4/extents.c
18 +++ b/fs/ext4/extents.c
19 @@ -701,9 +701,11 @@ static void ext4_ext_show_move(struct inode *inode, struct ext4_ext_path *path,
21  void ext4_ext_drop_refs(struct ext4_ext_path *path)
22  {
23 -       int depth = path->p_depth;
24 -       int i;
25 +       int depth, i;
27 +       if (!path)
28 +               return;
29 +       depth = path->p_depth;
30         for (i = 0; i <= depth; i++, path++)
31                 if (path->p_bh) {
32                         brelse(path->p_bh);
33 @@ -2117,10 +2119,8 @@ merge:
34         err = ext4_ext_dirty(handle, inode, path + path->p_depth);
36  cleanup:
37 -       if (npath) {
38 -               ext4_ext_drop_refs(npath);
39 -               kfree(npath);
40 -       }
41 +       ext4_ext_drop_refs(npath);
42 +       kfree(npath);
43         return err;
44  }
46 @@ -2275,11 +2275,8 @@ static int ext4_fill_fiemap_extents(struct inode *inode,
47                 block = es.es_lblk + es.es_len;
48         }
50 -       if (path) {
51 -               ext4_ext_drop_refs(path);
52 -               kfree(path);
53 -       }
55 +       ext4_ext_drop_refs(path);
56 +       kfree(path);
57         return err;
58  }
60 @@ -3010,11 +3007,9 @@ again:
61                 }
62         }
63  out:
64 -       if (path) {
65 -               ext4_ext_drop_refs(path);
66 -               kfree(path);
67 -               path = NULL;
68 -       }
69 +       ext4_ext_drop_refs(path);
70 +       kfree(path);
71 +       path = NULL;
72         if (err == -EAGAIN)
73                 goto again;
74         ext4_journal_stop(handle);
75 @@ -4617,10 +4612,8 @@ out:
76         map->m_pblk = newblock;
77         map->m_len = allocated;
78  out2:
79 -       if (path) {
80 -               ext4_ext_drop_refs(path);
81 -               kfree(path);
82 -       }
83 +       ext4_ext_drop_refs(path);
84 +       kfree(path);
86         trace_ext4_ext_map_blocks_exit(inode, flags, map,
87                                        err ? err : allocated);
88 @@ -5692,16 +5685,11 @@ ext4_swap_extents(handle_t *handle, struct inode *inode1,
89                 count -= len;
91         repeat:
92 -               if (path1) {
93 -                       ext4_ext_drop_refs(path1);
94 -                       kfree(path1);
95 -                       path1 = NULL;
96 -               }
97 -               if (path2) {
98 -                       ext4_ext_drop_refs(path2);
99 -                       kfree(path2);
100 -                       path2 = NULL;
101 -               }
102 +               ext4_ext_drop_refs(path1);
103 +               kfree(path1);
104 +               ext4_ext_drop_refs(path2);
105 +               kfree(path2);
106 +               path1 = path2 = NULL;
107         }
108         return replaced_count;
110 diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
111 index 0b7e28e..8ffff96 100644
112 --- a/fs/ext4/extents_status.c
113 +++ b/fs/ext4/extents_status.c
114 @@ -499,10 +499,8 @@ static void ext4_es_insert_extent_ext_check(struct inode *inode,
115                 }
116         }
117  out:
118 -       if (path) {
119 -               ext4_ext_drop_refs(path);
120 -               kfree(path);
121 -       }
122 +       ext4_ext_drop_refs(path);
123 +       kfree(path);
126  static void ext4_es_insert_extent_ind_check(struct inode *inode,
127 diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
128 index aff7bdf..061c300 100644
129 --- a/fs/ext4/migrate.c
130 +++ b/fs/ext4/migrate.c
131 @@ -84,10 +84,8 @@ static int finish_range(handle_t *handle, struct inode *inode,
132         retval = ext4_ext_insert_extent(handle, inode, &path, &newext, 0);
133  err_out:
134         up_write((&EXT4_I(inode)->i_data_sem));
135 -       if (path) {
136 -               ext4_ext_drop_refs(path);
137 -               kfree(path);
138 -       }
139 +       ext4_ext_drop_refs(path);
140 +       kfree(path);
141         lb->first_pblock = 0;
142         return retval;
144 diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
145 index 5e2465a..a34c076 100644
146 --- a/fs/ext4/move_extent.c
147 +++ b/fs/ext4/move_extent.c
148 @@ -113,10 +113,8 @@ mext_check_coverage(struct inode *inode, ext4_lblk_t from, ext4_lblk_t count,
149         }
150         ret = 1;
151  out:
152 -       if (path) {
153 -               ext4_ext_drop_refs(path);
154 -               kfree(path);
155 -       }
156 +       ext4_ext_drop_refs(path);
157 +       kfree(path);
158         return ret;
161 @@ -711,11 +709,9 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
162                 o_start += cur_len;
163                 d_start += cur_len;
164         repeat:
165 -               if (path) {
166 -                       ext4_ext_drop_refs(path);
167 -                       kfree(path);
168 -                       path = NULL;
169 -               }
170 +               ext4_ext_drop_refs(path);
171 +               kfree(path);
172 +               path = NULL;
173         }
174         *moved_len = o_start - orig_blk;
175         if (*moved_len > len)
176 @@ -727,10 +723,8 @@ out:
177                 ext4_discard_preallocations(donor_inode);
178         }
180 -       if (path) {
181 -               ext4_ext_drop_refs(path);
182 -               kfree(path);
183 -       }
184 +       ext4_ext_drop_refs(path);
185 +       kfree(path);
186         ext4_double_up_write_data_sem(orig_inode, donor_inode);
187         ext4_inode_resume_unlocked_dio(orig_inode);
188         ext4_inode_resume_unlocked_dio(donor_inode);