@@ -27,32 +27,26 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,
2727 u8 type , u64 subid )
2828{
2929 int ret ;
30- struct btrfs_path * path = NULL ;
30+ BTRFS_PATH_AUTO_FREE ( path ) ;
3131 struct extent_buffer * eb ;
3232 int slot ;
3333 u32 item_size ;
3434 unsigned long offset ;
3535 struct btrfs_key key ;
3636
37- if (WARN_ON_ONCE (!uuid_root )) {
38- ret = - ENOENT ;
39- goto out ;
40- }
37+ if (WARN_ON_ONCE (!uuid_root ))
38+ return - ENOENT ;
4139
4240 path = btrfs_alloc_path ();
43- if (!path ) {
44- ret = - ENOMEM ;
45- goto out ;
46- }
41+ if (!path )
42+ return - ENOMEM ;
4743
4844 btrfs_uuid_to_key (uuid , type , & key );
4945 ret = btrfs_search_slot (NULL , uuid_root , & key , path , 0 , 0 );
50- if (ret < 0 ) {
51- goto out ;
52- } else if (ret > 0 ) {
53- ret = - ENOENT ;
54- goto out ;
55- }
46+ if (ret < 0 )
47+ return ret ;
48+ if (ret > 0 )
49+ return - ENOENT ;
5650
5751 eb = path -> nodes [0 ];
5852 slot = path -> slots [0 ];
@@ -64,7 +58,7 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,
6458 btrfs_warn (uuid_root -> fs_info ,
6559 "uuid item with illegal size %lu!" ,
6660 (unsigned long )item_size );
67- goto out ;
61+ return ret ;
6862 }
6963 while (item_size ) {
7064 __le64 data ;
@@ -78,8 +72,6 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,
7872 item_size -= sizeof (data );
7973 }
8074
81- out :
82- btrfs_free_path (path );
8375 return ret ;
8476}
8577
@@ -89,7 +81,7 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typ
8981 struct btrfs_fs_info * fs_info = trans -> fs_info ;
9082 struct btrfs_root * uuid_root = fs_info -> uuid_root ;
9183 int ret ;
92- struct btrfs_path * path = NULL ;
84+ BTRFS_PATH_AUTO_FREE ( path ) ;
9385 struct btrfs_key key ;
9486 struct extent_buffer * eb ;
9587 int slot ;
@@ -100,18 +92,14 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typ
10092 if (ret != - ENOENT )
10193 return ret ;
10294
103- if (WARN_ON_ONCE (!uuid_root )) {
104- ret = - EINVAL ;
105- goto out ;
106- }
95+ if (WARN_ON_ONCE (!uuid_root ))
96+ return - EINVAL ;
10797
10898 btrfs_uuid_to_key (uuid , type , & key );
10999
110100 path = btrfs_alloc_path ();
111- if (!path ) {
112- ret = - ENOMEM ;
113- goto out ;
114- }
101+ if (!path )
102+ return - ENOMEM ;
115103
116104 ret = btrfs_insert_empty_item (trans , uuid_root , path , & key ,
117105 sizeof (subid_le ));
@@ -134,15 +122,12 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typ
134122 btrfs_warn (fs_info ,
135123 "insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!" ,
136124 ret , key .objectid , key .offset , type );
137- goto out ;
125+ return ret ;
138126 }
139127
140- ret = 0 ;
141128 subid_le = cpu_to_le64 (subid_cpu );
142129 write_extent_buffer (eb , & subid_le , offset , sizeof (subid_le ));
143- out :
144- btrfs_free_path (path );
145- return ret ;
130+ return 0 ;
146131}
147132
148133int btrfs_uuid_tree_remove (struct btrfs_trans_handle * trans , const u8 * uuid , u8 type ,
@@ -151,7 +136,7 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
151136 struct btrfs_fs_info * fs_info = trans -> fs_info ;
152137 struct btrfs_root * uuid_root = fs_info -> uuid_root ;
153138 int ret ;
154- struct btrfs_path * path = NULL ;
139+ BTRFS_PATH_AUTO_FREE ( path ) ;
155140 struct btrfs_key key ;
156141 struct extent_buffer * eb ;
157142 int slot ;
@@ -161,29 +146,23 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
161146 unsigned long move_src ;
162147 unsigned long move_len ;
163148
164- if (WARN_ON_ONCE (!uuid_root )) {
165- ret = - EINVAL ;
166- goto out ;
167- }
149+ if (WARN_ON_ONCE (!uuid_root ))
150+ return - EINVAL ;
168151
169152 btrfs_uuid_to_key (uuid , type , & key );
170153
171154 path = btrfs_alloc_path ();
172- if (!path ) {
173- ret = - ENOMEM ;
174- goto out ;
175- }
155+ if (!path )
156+ return - ENOMEM ;
176157
177158 ret = btrfs_search_slot (trans , uuid_root , & key , path , -1 , 1 );
178159 if (ret < 0 ) {
179160 btrfs_warn (fs_info , "error %d while searching for uuid item!" ,
180161 ret );
181- goto out ;
182- }
183- if (ret > 0 ) {
184- ret = - ENOENT ;
185- goto out ;
162+ return ret ;
186163 }
164+ if (ret > 0 )
165+ return - ENOENT ;
187166
188167 eb = path -> nodes [0 ];
189168 slot = path -> slots [0 ];
@@ -192,8 +171,7 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
192171 if (!IS_ALIGNED (item_size , sizeof (u64 ))) {
193172 btrfs_warn (fs_info , "uuid item with illegal size %lu!" ,
194173 (unsigned long )item_size );
195- ret = - ENOENT ;
196- goto out ;
174+ return - ENOENT ;
197175 }
198176 while (item_size ) {
199177 __le64 read_subid ;
@@ -205,26 +183,20 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
205183 item_size -= sizeof (read_subid );
206184 }
207185
208- if (!item_size ) {
209- ret = - ENOENT ;
210- goto out ;
211- }
186+ if (!item_size )
187+ return - ENOENT ;
212188
213189 item_size = btrfs_item_size (eb , slot );
214- if (item_size == sizeof (subid )) {
215- ret = btrfs_del_item (trans , uuid_root , path );
216- goto out ;
217- }
190+ if (item_size == sizeof (subid ))
191+ return btrfs_del_item (trans , uuid_root , path );
218192
219193 move_dst = offset ;
220194 move_src = offset + sizeof (subid );
221195 move_len = item_size - (move_src - btrfs_item_ptr_offset (eb , slot ));
222196 memmove_extent_buffer (eb , move_dst , move_src , move_len );
223197 btrfs_truncate_item (trans , path , item_size - sizeof (subid ), 1 );
224198
225- out :
226- btrfs_free_path (path );
227- return ret ;
199+ return 0 ;
228200}
229201
230202static int btrfs_uuid_iter_rem (struct btrfs_root * uuid_root , u8 * uuid , u8 type ,
@@ -293,36 +265,32 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
293265{
294266 struct btrfs_root * root = fs_info -> uuid_root ;
295267 struct btrfs_key key ;
296- struct btrfs_path * path ;
268+ BTRFS_PATH_AUTO_FREE ( path ) ;
297269 int ret = 0 ;
298270 struct extent_buffer * leaf ;
299271 int slot ;
300272 u32 item_size ;
301273 unsigned long offset ;
302274
303275 path = btrfs_alloc_path ();
304- if (!path ) {
305- ret = - ENOMEM ;
306- goto out ;
307- }
276+ if (!path )
277+ return - ENOMEM ;
308278
309279 key .objectid = 0 ;
310280 key .type = 0 ;
311281 key .offset = 0 ;
312282
313283again_search_slot :
314284 ret = btrfs_search_forward (root , & key , path , BTRFS_OLDEST_GENERATION );
315- if (ret ) {
316- if (ret > 0 )
317- ret = 0 ;
318- goto out ;
319- }
285+ if (ret < 0 )
286+ return ret ;
287+ if (ret > 0 )
288+ return 0 ;
320289
321290 while (1 ) {
322- if (btrfs_fs_closing (fs_info )) {
323- ret = - EINTR ;
324- goto out ;
325- }
291+ if (btrfs_fs_closing (fs_info ))
292+ return - EINTR ;
293+
326294 cond_resched ();
327295 leaf = path -> nodes [0 ];
328296 slot = path -> slots [0 ];
@@ -353,7 +321,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
353321 ret = btrfs_check_uuid_tree_entry (fs_info , uuid ,
354322 key .type , subid_cpu );
355323 if (ret < 0 )
356- goto out ;
324+ return ret ;
357325 if (ret > 0 ) {
358326 btrfs_release_path (path );
359327 ret = btrfs_uuid_iter_rem (root , uuid , key .type ,
@@ -369,7 +337,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
369337 goto again_search_slot ;
370338 }
371339 if (ret < 0 && ret != - ENOENT )
372- goto out ;
340+ return ret ;
373341 key .offset ++ ;
374342 goto again_search_slot ;
375343 }
@@ -386,8 +354,6 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
386354 break ;
387355 }
388356
389- out :
390- btrfs_free_path (path );
391357 return ret ;
392358}
393359
0 commit comments