Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: more trivial BTRFS_PATH_AUTO_FREE conversions

Convert more of the trivial pattern for the auto freeing of btrfs_path
with goto -> return conversions where applicable.

Signed-off-by: Sun YangKai <sunk67188@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Sun YangKai and committed by
David Sterba
7fc35cc5 a1359d06

+119 -219
+43 -77
fs/btrfs/uuid-tree.c
··· 27 27 u8 type, u64 subid) 28 28 { 29 29 int ret; 30 - struct btrfs_path *path = NULL; 30 + BTRFS_PATH_AUTO_FREE(path); 31 31 struct extent_buffer *eb; 32 32 int slot; 33 33 u32 item_size; 34 34 unsigned long offset; 35 35 struct btrfs_key key; 36 36 37 - if (WARN_ON_ONCE(!uuid_root)) { 38 - ret = -ENOENT; 39 - goto out; 40 - } 37 + if (WARN_ON_ONCE(!uuid_root)) 38 + return -ENOENT; 41 39 42 40 path = btrfs_alloc_path(); 43 - if (!path) { 44 - ret = -ENOMEM; 45 - goto out; 46 - } 41 + if (!path) 42 + return -ENOMEM; 47 43 48 44 btrfs_uuid_to_key(uuid, type, &key); 49 45 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; 56 50 57 51 eb = path->nodes[0]; 58 52 slot = path->slots[0]; ··· 58 64 btrfs_warn(uuid_root->fs_info, 59 65 "uuid item with illegal size %lu!", 60 66 (unsigned long)item_size); 61 - goto out; 67 + return ret; 62 68 } 63 69 while (item_size) { 64 70 __le64 data; ··· 72 78 item_size -= sizeof(data); 73 79 } 74 80 75 - out: 76 - btrfs_free_path(path); 77 81 return ret; 78 82 } 79 83 ··· 81 89 struct btrfs_fs_info *fs_info = trans->fs_info; 82 90 struct btrfs_root *uuid_root = fs_info->uuid_root; 83 91 int ret; 84 - struct btrfs_path *path = NULL; 92 + BTRFS_PATH_AUTO_FREE(path); 85 93 struct btrfs_key key; 86 94 struct extent_buffer *eb; 87 95 int slot; ··· 92 100 if (ret != -ENOENT) 93 101 return ret; 94 102 95 - if (WARN_ON_ONCE(!uuid_root)) { 96 - ret = -EINVAL; 97 - goto out; 98 - } 103 + if (WARN_ON_ONCE(!uuid_root)) 104 + return -EINVAL; 99 105 100 106 btrfs_uuid_to_key(uuid, type, &key); 101 107 102 108 path = btrfs_alloc_path(); 103 - if (!path) { 104 - ret = -ENOMEM; 105 - goto out; 106 - } 109 + if (!path) 110 + return -ENOMEM; 107 111 108 112 ret = btrfs_insert_empty_item(trans, uuid_root, path, &key, 109 113 sizeof(subid_le)); ··· 122 134 btrfs_warn(fs_info, 123 135 "insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!", 124 136 ret, key.objectid, key.offset, type); 125 - goto out; 137 + return ret; 126 138 } 127 139 128 - ret = 0; 129 140 subid_le = cpu_to_le64(subid_cpu); 130 141 write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le)); 131 - out: 132 - btrfs_free_path(path); 133 - return ret; 142 + return 0; 134 143 } 135 144 136 145 int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8 type, ··· 136 151 struct btrfs_fs_info *fs_info = trans->fs_info; 137 152 struct btrfs_root *uuid_root = fs_info->uuid_root; 138 153 int ret; 139 - struct btrfs_path *path = NULL; 154 + BTRFS_PATH_AUTO_FREE(path); 140 155 struct btrfs_key key; 141 156 struct extent_buffer *eb; 142 157 int slot; ··· 146 161 unsigned long move_src; 147 162 unsigned long move_len; 148 163 149 - if (WARN_ON_ONCE(!uuid_root)) { 150 - ret = -EINVAL; 151 - goto out; 152 - } 164 + if (WARN_ON_ONCE(!uuid_root)) 165 + return -EINVAL; 153 166 154 167 btrfs_uuid_to_key(uuid, type, &key); 155 168 156 169 path = btrfs_alloc_path(); 157 - if (!path) { 158 - ret = -ENOMEM; 159 - goto out; 160 - } 170 + if (!path) 171 + return -ENOMEM; 161 172 162 173 ret = btrfs_search_slot(trans, uuid_root, &key, path, -1, 1); 163 174 if (ret < 0) { 164 175 btrfs_warn(fs_info, "error %d while searching for uuid item!", 165 176 ret); 166 - goto out; 177 + return ret; 167 178 } 168 - if (ret > 0) { 169 - ret = -ENOENT; 170 - goto out; 171 - } 179 + if (ret > 0) 180 + return -ENOENT; 172 181 173 182 eb = path->nodes[0]; 174 183 slot = path->slots[0]; ··· 171 192 if (!IS_ALIGNED(item_size, sizeof(u64))) { 172 193 btrfs_warn(fs_info, "uuid item with illegal size %lu!", 173 194 (unsigned long)item_size); 174 - ret = -ENOENT; 175 - goto out; 195 + return -ENOENT; 176 196 } 177 197 while (item_size) { 178 198 __le64 read_subid; ··· 183 205 item_size -= sizeof(read_subid); 184 206 } 185 207 186 - if (!item_size) { 187 - ret = -ENOENT; 188 - goto out; 189 - } 208 + if (!item_size) 209 + return -ENOENT; 190 210 191 211 item_size = btrfs_item_size(eb, slot); 192 - if (item_size == sizeof(subid)) { 193 - ret = btrfs_del_item(trans, uuid_root, path); 194 - goto out; 195 - } 212 + if (item_size == sizeof(subid)) 213 + return btrfs_del_item(trans, uuid_root, path); 196 214 197 215 move_dst = offset; 198 216 move_src = offset + sizeof(subid); ··· 196 222 memmove_extent_buffer(eb, move_dst, move_src, move_len); 197 223 btrfs_truncate_item(trans, path, item_size - sizeof(subid), 1); 198 224 199 - out: 200 - btrfs_free_path(path); 201 - return ret; 225 + return 0; 202 226 } 203 227 204 228 static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type, ··· 265 293 { 266 294 struct btrfs_root *root = fs_info->uuid_root; 267 295 struct btrfs_key key; 268 - struct btrfs_path *path; 296 + BTRFS_PATH_AUTO_FREE(path); 269 297 int ret = 0; 270 298 struct extent_buffer *leaf; 271 299 int slot; ··· 273 301 unsigned long offset; 274 302 275 303 path = btrfs_alloc_path(); 276 - if (!path) { 277 - ret = -ENOMEM; 278 - goto out; 279 - } 304 + if (!path) 305 + return -ENOMEM; 280 306 281 307 key.objectid = 0; 282 308 key.type = 0; ··· 282 312 283 313 again_search_slot: 284 314 ret = btrfs_search_forward(root, &key, path, BTRFS_OLDEST_GENERATION); 285 - if (ret) { 286 - if (ret > 0) 287 - ret = 0; 288 - goto out; 289 - } 315 + if (ret < 0) 316 + return ret; 317 + if (ret > 0) 318 + return 0; 290 319 291 320 while (1) { 292 - if (btrfs_fs_closing(fs_info)) { 293 - ret = -EINTR; 294 - goto out; 295 - } 321 + if (btrfs_fs_closing(fs_info)) 322 + return -EINTR; 323 + 296 324 cond_resched(); 297 325 leaf = path->nodes[0]; 298 326 slot = path->slots[0]; ··· 321 353 ret = btrfs_check_uuid_tree_entry(fs_info, uuid, 322 354 key.type, subid_cpu); 323 355 if (ret < 0) 324 - goto out; 356 + return ret; 325 357 if (ret > 0) { 326 358 btrfs_release_path(path); 327 359 ret = btrfs_uuid_iter_rem(root, uuid, key.type, ··· 337 369 goto again_search_slot; 338 370 } 339 371 if (ret < 0 && ret != -ENOENT) 340 - goto out; 372 + return ret; 341 373 key.offset++; 342 374 goto again_search_slot; 343 375 } ··· 354 386 break; 355 387 } 356 388 357 - out: 358 - btrfs_free_path(path); 359 389 return ret; 360 390 } 361 391
+10 -19
fs/btrfs/verity.c
··· 109 109 { 110 110 struct btrfs_trans_handle *trans; 111 111 struct btrfs_root *root = inode->root; 112 - struct btrfs_path *path; 112 + BTRFS_PATH_AUTO_FREE(path); 113 113 struct btrfs_key key; 114 114 int count = 0; 115 115 int ret; ··· 121 121 while (1) { 122 122 /* 1 for the item being dropped */ 123 123 trans = btrfs_start_transaction(root, 1); 124 - if (IS_ERR(trans)) { 125 - ret = PTR_ERR(trans); 126 - goto out; 127 - } 124 + if (IS_ERR(trans)) 125 + return PTR_ERR(trans); 128 126 129 127 /* 130 128 * Walk backwards through all the items until we find one that ··· 141 143 path->slots[0]--; 142 144 } else if (ret < 0) { 143 145 btrfs_end_transaction(trans); 144 - goto out; 146 + return ret; 145 147 } 146 148 147 149 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); ··· 159 161 ret = btrfs_del_items(trans, root, path, path->slots[0], 1); 160 162 if (ret) { 161 163 btrfs_end_transaction(trans); 162 - goto out; 164 + return ret; 163 165 } 164 166 count++; 165 167 btrfs_release_path(path); 166 168 btrfs_end_transaction(trans); 167 169 } 168 - ret = count; 169 170 btrfs_end_transaction(trans); 170 - out: 171 - btrfs_free_path(path); 172 - return ret; 171 + return count; 173 172 } 174 173 175 174 /* ··· 212 217 const char *src, u64 len) 213 218 { 214 219 struct btrfs_trans_handle *trans; 215 - struct btrfs_path *path; 220 + BTRFS_PATH_AUTO_FREE(path); 216 221 struct btrfs_root *root = inode->root; 217 222 struct extent_buffer *leaf; 218 223 struct btrfs_key key; ··· 228 233 while (len > 0) { 229 234 /* 1 for the new item being inserted */ 230 235 trans = btrfs_start_transaction(root, 1); 231 - if (IS_ERR(trans)) { 232 - ret = PTR_ERR(trans); 233 - break; 234 - } 236 + if (IS_ERR(trans)) 237 + return PTR_ERR(trans); 235 238 236 239 key.objectid = btrfs_ino(inode); 237 240 key.type = key_type; ··· 260 267 btrfs_end_transaction(trans); 261 268 } 262 269 263 - btrfs_free_path(path); 264 270 return ret; 265 271 } 266 272 ··· 288 296 static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, 289 297 char *dest, u64 len, struct folio *dest_folio) 290 298 { 291 - struct btrfs_path *path; 299 + BTRFS_PATH_AUTO_FREE(path); 292 300 struct btrfs_root *root = inode->root; 293 301 struct extent_buffer *leaf; 294 302 struct btrfs_key key; ··· 396 404 } 397 405 } 398 406 out: 399 - btrfs_free_path(path); 400 407 if (!ret) 401 408 ret = copied; 402 409 return ret;
+55 -98
fs/btrfs/volumes.c
··· 1681 1681 struct btrfs_root *root = fs_info->dev_root; 1682 1682 struct btrfs_key key; 1683 1683 struct btrfs_dev_extent *dev_extent; 1684 - struct btrfs_path *path; 1684 + BTRFS_PATH_AUTO_FREE(path); 1685 1685 u64 search_start; 1686 1686 u64 hole_size; 1687 1687 u64 max_hole_start; ··· 1812 1812 "max_hole_start=%llu max_hole_size=%llu search_end=%llu", 1813 1813 max_hole_start, max_hole_size, search_end); 1814 1814 out: 1815 - btrfs_free_path(path); 1816 1815 *start = max_hole_start; 1817 1816 if (len) 1818 1817 *len = max_hole_size; ··· 1825 1826 struct btrfs_fs_info *fs_info = device->fs_info; 1826 1827 struct btrfs_root *root = fs_info->dev_root; 1827 1828 int ret; 1828 - struct btrfs_path *path; 1829 + BTRFS_PATH_AUTO_FREE(path); 1829 1830 struct btrfs_key key; 1830 1831 struct btrfs_key found_key; 1831 1832 struct extent_buffer *leaf = NULL; ··· 1844 1845 ret = btrfs_previous_item(root, path, key.objectid, 1845 1846 BTRFS_DEV_EXTENT_KEY); 1846 1847 if (ret) 1847 - goto out; 1848 + return ret; 1848 1849 leaf = path->nodes[0]; 1849 1850 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); 1850 1851 extent = btrfs_item_ptr(leaf, path->slots[0], ··· 1859 1860 extent = btrfs_item_ptr(leaf, path->slots[0], 1860 1861 struct btrfs_dev_extent); 1861 1862 } else { 1862 - goto out; 1863 + return ret; 1863 1864 } 1864 1865 1865 1866 *dev_extent_len = btrfs_dev_extent_length(leaf, extent); ··· 1867 1868 ret = btrfs_del_item(trans, root, path); 1868 1869 if (ret == 0) 1869 1870 set_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags); 1870 - out: 1871 - btrfs_free_path(path); 1872 1871 return ret; 1873 1872 } 1874 1873 ··· 1894 1897 int ret; 1895 1898 struct btrfs_key key; 1896 1899 struct btrfs_key found_key; 1897 - struct btrfs_path *path; 1900 + BTRFS_PATH_AUTO_FREE(path); 1898 1901 1899 1902 path = btrfs_alloc_path(); 1900 1903 if (!path) ··· 1906 1909 1907 1910 ret = btrfs_search_slot(NULL, fs_info->chunk_root, &key, path, 0, 0); 1908 1911 if (ret < 0) 1909 - goto error; 1912 + return ret; 1910 1913 1911 1914 if (unlikely(ret == 0)) { 1912 1915 /* Corruption */ 1913 1916 btrfs_err(fs_info, "corrupted chunk tree devid -1 matched"); 1914 - ret = -EUCLEAN; 1915 - goto error; 1917 + return -EUCLEAN; 1916 1918 } 1917 1919 1918 1920 ret = btrfs_previous_item(fs_info->chunk_root, path, ··· 1924 1928 path->slots[0]); 1925 1929 *devid_ret = found_key.offset + 1; 1926 1930 } 1927 - ret = 0; 1928 - error: 1929 - btrfs_free_path(path); 1930 - return ret; 1931 + return 0; 1931 1932 } 1932 1933 1933 1934 /* ··· 1935 1942 struct btrfs_device *device) 1936 1943 { 1937 1944 int ret; 1938 - struct btrfs_path *path; 1945 + BTRFS_PATH_AUTO_FREE(path); 1939 1946 struct btrfs_dev_item *dev_item; 1940 1947 struct extent_buffer *leaf; 1941 1948 struct btrfs_key key; ··· 1954 1961 &key, sizeof(*dev_item)); 1955 1962 btrfs_trans_release_chunk_metadata(trans); 1956 1963 if (ret) 1957 - goto out; 1964 + return ret; 1958 1965 1959 1966 leaf = path->nodes[0]; 1960 1967 dev_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_item); ··· 1980 1987 write_extent_buffer(leaf, trans->fs_info->fs_devices->metadata_uuid, 1981 1988 ptr, BTRFS_FSID_SIZE); 1982 1989 1983 - ret = 0; 1984 - out: 1985 - btrfs_free_path(path); 1986 - return ret; 1990 + return 0; 1987 1991 } 1988 1992 1989 1993 /* ··· 2007 2017 { 2008 2018 struct btrfs_root *root = device->fs_info->chunk_root; 2009 2019 int ret; 2010 - struct btrfs_path *path; 2020 + BTRFS_PATH_AUTO_FREE(path); 2011 2021 struct btrfs_key key; 2012 2022 2013 2023 path = btrfs_alloc_path(); ··· 2021 2031 btrfs_reserve_chunk_metadata(trans, false); 2022 2032 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 2023 2033 btrfs_trans_release_chunk_metadata(trans); 2024 - if (ret) { 2025 - if (ret > 0) 2026 - ret = -ENOENT; 2027 - goto out; 2028 - } 2034 + if (ret > 0) 2035 + return -ENOENT; 2036 + if (ret < 0) 2037 + return ret; 2029 2038 2030 - ret = btrfs_del_item(trans, root, path); 2031 - out: 2032 - btrfs_free_path(path); 2033 - return ret; 2039 + return btrfs_del_item(trans, root, path); 2034 2040 } 2035 2041 2036 2042 /* ··· 2612 2626 BTRFS_DEV_LOOKUP_ARGS(args); 2613 2627 struct btrfs_fs_info *fs_info = trans->fs_info; 2614 2628 struct btrfs_root *root = fs_info->chunk_root; 2615 - struct btrfs_path *path; 2629 + BTRFS_PATH_AUTO_FREE(path); 2616 2630 struct extent_buffer *leaf; 2617 2631 struct btrfs_dev_item *dev_item; 2618 2632 struct btrfs_device *device; ··· 2634 2648 ret = btrfs_search_slot(trans, root, &key, path, 0, 1); 2635 2649 btrfs_trans_release_chunk_metadata(trans); 2636 2650 if (ret < 0) 2637 - goto error; 2651 + return ret; 2638 2652 2639 2653 leaf = path->nodes[0]; 2640 2654 next_slot: ··· 2643 2657 if (ret > 0) 2644 2658 break; 2645 2659 if (ret < 0) 2646 - goto error; 2660 + return ret; 2647 2661 leaf = path->nodes[0]; 2648 2662 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); 2649 2663 btrfs_release_path(path); ··· 2674 2688 path->slots[0]++; 2675 2689 goto next_slot; 2676 2690 } 2677 - ret = 0; 2678 - error: 2679 - btrfs_free_path(path); 2680 - return ret; 2691 + return 0; 2681 2692 } 2682 2693 2683 2694 int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path) ··· 2929 2946 struct btrfs_device *device) 2930 2947 { 2931 2948 int ret; 2932 - struct btrfs_path *path; 2949 + BTRFS_PATH_AUTO_FREE(path); 2933 2950 struct btrfs_root *root = device->fs_info->chunk_root; 2934 2951 struct btrfs_dev_item *dev_item; 2935 2952 struct extent_buffer *leaf; ··· 2945 2962 2946 2963 ret = btrfs_search_slot(trans, root, &key, path, 0, 1); 2947 2964 if (ret < 0) 2948 - goto out; 2965 + return ret; 2949 2966 2950 - if (ret > 0) { 2951 - ret = -ENOENT; 2952 - goto out; 2953 - } 2967 + if (ret > 0) 2968 + return -ENOENT; 2954 2969 2955 2970 leaf = path->nodes[0]; 2956 2971 dev_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_item); ··· 2962 2981 btrfs_device_get_disk_total_bytes(device)); 2963 2982 btrfs_set_device_bytes_used(leaf, dev_item, 2964 2983 btrfs_device_get_bytes_used(device)); 2965 - out: 2966 - btrfs_free_path(path); 2967 2984 return ret; 2968 2985 } 2969 2986 ··· 3014 3035 struct btrfs_fs_info *fs_info = trans->fs_info; 3015 3036 struct btrfs_root *root = fs_info->chunk_root; 3016 3037 int ret; 3017 - struct btrfs_path *path; 3038 + BTRFS_PATH_AUTO_FREE(path); 3018 3039 struct btrfs_key key; 3019 3040 3020 3041 path = btrfs_alloc_path(); ··· 3027 3048 3028 3049 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 3029 3050 if (ret < 0) 3030 - goto out; 3031 - else if (unlikely(ret > 0)) { /* Logic error or corruption */ 3051 + return ret; 3052 + if (unlikely(ret > 0)) { 3053 + /* Logic error or corruption */ 3032 3054 btrfs_err(fs_info, "failed to lookup chunk %llu when freeing", 3033 3055 chunk_offset); 3034 3056 btrfs_abort_transaction(trans, -ENOENT); 3035 - ret = -EUCLEAN; 3036 - goto out; 3057 + return -EUCLEAN; 3037 3058 } 3038 3059 3039 3060 ret = btrfs_del_item(trans, root, path); 3040 3061 if (unlikely(ret < 0)) { 3041 3062 btrfs_err(fs_info, "failed to delete chunk %llu item", chunk_offset); 3042 3063 btrfs_abort_transaction(trans, ret); 3043 - goto out; 3064 + return ret; 3044 3065 } 3045 - out: 3046 - btrfs_free_path(path); 3047 3066 return ret; 3048 3067 } 3049 3068 ··· 3478 3501 static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info) 3479 3502 { 3480 3503 struct btrfs_root *chunk_root = fs_info->chunk_root; 3481 - struct btrfs_path *path; 3504 + BTRFS_PATH_AUTO_FREE(path); 3482 3505 struct extent_buffer *leaf; 3483 3506 struct btrfs_chunk *chunk; 3484 3507 struct btrfs_key key; ··· 3502 3525 ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0); 3503 3526 if (ret < 0) { 3504 3527 mutex_unlock(&fs_info->reclaim_bgs_lock); 3505 - goto error; 3528 + return ret; 3506 3529 } 3507 3530 if (unlikely(ret == 0)) { 3508 3531 /* ··· 3512 3535 * offset (one less than the previous one, wrong 3513 3536 * alignment and size). 3514 3537 */ 3515 - ret = -EUCLEAN; 3516 3538 mutex_unlock(&fs_info->reclaim_bgs_lock); 3517 - goto error; 3539 + return -EUCLEAN; 3518 3540 } 3519 3541 3520 3542 ret = btrfs_previous_item(chunk_root, path, key.objectid, ··· 3521 3545 if (ret) 3522 3546 mutex_unlock(&fs_info->reclaim_bgs_lock); 3523 3547 if (ret < 0) 3524 - goto error; 3548 + return ret; 3525 3549 if (ret > 0) 3526 3550 break; 3527 3551 ··· 3555 3579 } else if (WARN_ON(failed && retried)) { 3556 3580 ret = -ENOSPC; 3557 3581 } 3558 - error: 3559 - btrfs_free_path(path); 3560 3582 return ret; 3561 3583 } 3562 3584 ··· 4683 4709 struct btrfs_balance_control *bctl; 4684 4710 struct btrfs_balance_item *item; 4685 4711 struct btrfs_disk_balance_args disk_bargs; 4686 - struct btrfs_path *path; 4712 + BTRFS_PATH_AUTO_FREE(path); 4687 4713 struct extent_buffer *leaf; 4688 4714 struct btrfs_key key; 4689 4715 int ret; ··· 4698 4724 4699 4725 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); 4700 4726 if (ret < 0) 4701 - goto out; 4727 + return ret; 4702 4728 if (ret > 0) { /* ret = -ENOENT; */ 4703 - ret = 0; 4704 - goto out; 4729 + return 0; 4705 4730 } 4706 4731 4707 4732 bctl = kzalloc(sizeof(*bctl), GFP_NOFS); 4708 - if (!bctl) { 4709 - ret = -ENOMEM; 4710 - goto out; 4711 - } 4733 + if (!bctl) 4734 + return -ENOMEM; 4712 4735 4713 4736 leaf = path->nodes[0]; 4714 4737 item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item); ··· 4742 4771 fs_info->balance_ctl = bctl; 4743 4772 spin_unlock(&fs_info->balance_lock); 4744 4773 mutex_unlock(&fs_info->balance_mutex); 4745 - out: 4746 - btrfs_free_path(path); 4747 4774 return ret; 4748 4775 } 4749 4776 ··· 7421 7452 int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info) 7422 7453 { 7423 7454 struct btrfs_root *root = fs_info->chunk_root; 7424 - struct btrfs_path *path; 7455 + BTRFS_PATH_AUTO_FREE(path); 7425 7456 struct extent_buffer *leaf; 7426 7457 struct btrfs_key key; 7427 7458 struct btrfs_key found_key; ··· 7538 7569 ret = 0; 7539 7570 error: 7540 7571 mutex_unlock(&uuid_mutex); 7541 - 7542 - btrfs_free_path(path); 7543 7572 return ret; 7544 7573 } 7545 7574 ··· 7637 7670 { 7638 7671 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs; 7639 7672 struct btrfs_device *device; 7640 - struct btrfs_path *path = NULL; 7673 + BTRFS_PATH_AUTO_FREE(path); 7641 7674 int ret = 0; 7642 7675 7643 7676 path = btrfs_alloc_path(); ··· 7659 7692 } 7660 7693 out: 7661 7694 mutex_unlock(&fs_devices->device_list_mutex); 7662 - 7663 - btrfs_free_path(path); 7664 7695 return ret; 7665 7696 } 7666 7697 ··· 7667 7702 { 7668 7703 struct btrfs_fs_info *fs_info = trans->fs_info; 7669 7704 struct btrfs_root *dev_root = fs_info->dev_root; 7670 - struct btrfs_path *path; 7705 + BTRFS_PATH_AUTO_FREE(path); 7671 7706 struct btrfs_key key; 7672 7707 struct extent_buffer *eb; 7673 7708 struct btrfs_dev_stats_item *ptr; ··· 7686 7721 btrfs_warn(fs_info, 7687 7722 "error %d while searching for dev_stats item for device %s", 7688 7723 ret, btrfs_dev_name(device)); 7689 - goto out; 7724 + return ret; 7690 7725 } 7691 7726 7692 7727 if (ret == 0 && ··· 7697 7732 btrfs_warn(fs_info, 7698 7733 "delete too small dev_stats item for device %s failed %d", 7699 7734 btrfs_dev_name(device), ret); 7700 - goto out; 7735 + return ret; 7701 7736 } 7702 7737 ret = 1; 7703 7738 } ··· 7711 7746 btrfs_warn(fs_info, 7712 7747 "insert dev_stats item for device %s failed %d", 7713 7748 btrfs_dev_name(device), ret); 7714 - goto out; 7749 + return ret; 7715 7750 } 7716 7751 } 7717 7752 ··· 7720 7755 for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++) 7721 7756 btrfs_set_dev_stats_value(eb, ptr, i, 7722 7757 btrfs_dev_stat_read(device, i)); 7723 - out: 7724 - btrfs_free_path(path); 7725 7758 return ret; 7726 7759 } 7727 7760 ··· 8009 8046 */ 8010 8047 int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info) 8011 8048 { 8012 - struct btrfs_path *path; 8049 + BTRFS_PATH_AUTO_FREE(path); 8013 8050 struct btrfs_root *root = fs_info->dev_root; 8014 8051 struct btrfs_key key; 8015 8052 u64 prev_devid = 0; ··· 8040 8077 path->reada = READA_FORWARD; 8041 8078 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 8042 8079 if (ret < 0) 8043 - goto out; 8080 + return ret; 8044 8081 8045 8082 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { 8046 8083 ret = btrfs_next_leaf(root, path); 8047 8084 if (ret < 0) 8048 - goto out; 8085 + return ret; 8049 8086 /* No dev extents at all? Not good */ 8050 - if (unlikely(ret > 0)) { 8051 - ret = -EUCLEAN; 8052 - goto out; 8053 - } 8087 + if (unlikely(ret > 0)) 8088 + return -EUCLEAN; 8054 8089 } 8055 8090 while (1) { 8056 8091 struct extent_buffer *leaf = path->nodes[0]; ··· 8074 8113 btrfs_err(fs_info, 8075 8114 "dev extent devid %llu physical offset %llu overlap with previous dev extent end %llu", 8076 8115 devid, physical_offset, prev_dev_ext_end); 8077 - ret = -EUCLEAN; 8078 - goto out; 8116 + return -EUCLEAN; 8079 8117 } 8080 8118 8081 8119 ret = verify_one_dev_extent(fs_info, chunk_offset, devid, 8082 8120 physical_offset, physical_len); 8083 8121 if (ret < 0) 8084 - goto out; 8122 + return ret; 8085 8123 prev_devid = devid; 8086 8124 prev_dev_ext_end = physical_offset + physical_len; 8087 8125 8088 8126 ret = btrfs_next_item(root, path); 8089 8127 if (ret < 0) 8090 - goto out; 8128 + return ret; 8091 8129 if (ret > 0) { 8092 8130 ret = 0; 8093 8131 break; ··· 8094 8134 } 8095 8135 8096 8136 /* Ensure all chunks have corresponding dev extents */ 8097 - ret = verify_chunk_dev_extent_mapping(fs_info); 8098 - out: 8099 - btrfs_free_path(path); 8100 - return ret; 8137 + return verify_chunk_dev_extent_mapping(fs_info); 8101 8138 } 8102 8139 8103 8140 /*
+11 -25
fs/btrfs/xattr.c
··· 29 29 { 30 30 struct btrfs_dir_item *di; 31 31 struct btrfs_root *root = BTRFS_I(inode)->root; 32 - struct btrfs_path *path; 32 + BTRFS_PATH_AUTO_FREE(path); 33 33 struct extent_buffer *leaf; 34 - int ret = 0; 35 34 unsigned long data_ptr; 36 35 37 36 path = btrfs_alloc_path(); ··· 40 41 /* lookup the xattr by name */ 41 42 di = btrfs_lookup_xattr(NULL, root, path, btrfs_ino(BTRFS_I(inode)), 42 43 name, strlen(name), 0); 43 - if (!di) { 44 - ret = -ENODATA; 45 - goto out; 46 - } else if (IS_ERR(di)) { 47 - ret = PTR_ERR(di); 48 - goto out; 49 - } 44 + if (!di) 45 + return -ENODATA; 46 + if (IS_ERR(di)) 47 + return PTR_ERR(di); 50 48 51 49 leaf = path->nodes[0]; 52 50 /* if size is 0, that means we want the size of the attr */ 53 - if (!size) { 54 - ret = btrfs_dir_data_len(leaf, di); 55 - goto out; 56 - } 51 + if (!size) 52 + return btrfs_dir_data_len(leaf, di); 57 53 58 54 /* now get the data out of our dir_item */ 59 - if (btrfs_dir_data_len(leaf, di) > size) { 60 - ret = -ERANGE; 61 - goto out; 62 - } 55 + if (btrfs_dir_data_len(leaf, di) > size) 56 + return -ERANGE; 63 57 64 58 /* 65 59 * The way things are packed into the leaf is like this ··· 65 73 btrfs_dir_name_len(leaf, di)); 66 74 read_extent_buffer(leaf, buffer, data_ptr, 67 75 btrfs_dir_data_len(leaf, di)); 68 - ret = btrfs_dir_data_len(leaf, di); 69 - 70 - out: 71 - btrfs_free_path(path); 72 - return ret; 76 + return btrfs_dir_data_len(leaf, di); 73 77 } 74 78 75 79 int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode, ··· 266 278 struct btrfs_key key; 267 279 struct inode *inode = d_inode(dentry); 268 280 struct btrfs_root *root = BTRFS_I(inode)->root; 269 - struct btrfs_path *path; 281 + BTRFS_PATH_AUTO_FREE(path); 270 282 int iter_ret = 0; 271 283 int ret = 0; 272 284 size_t total_size = 0, size_left = size; ··· 341 353 ret = iter_ret; 342 354 else 343 355 ret = total_size; 344 - 345 - btrfs_free_path(path); 346 356 347 357 return ret; 348 358 }