Commit 45763a0c authored by Leo Martins's avatar Leo Martins Committed by David Sterba

btrfs: use btrfs_path auto free in zoned.c

All cleanup paths lead to btrfs_path_free so path can be defined with
the automatic freeing callback in the following functions:

- calculate_emulated_zone_size()
- calculate_alloc_pointer()
Signed-off-by: default avatarLeo Martins <loemra.dev@gmail.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 4c74a32a
...@@ -287,7 +287,7 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos, ...@@ -287,7 +287,7 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos,
/* The emulated zone size is determined from the size of device extent */ /* The emulated zone size is determined from the size of device extent */
static int calculate_emulated_zone_size(struct btrfs_fs_info *fs_info) static int calculate_emulated_zone_size(struct btrfs_fs_info *fs_info)
{ {
struct btrfs_path *path; BTRFS_PATH_AUTO_FREE(path);
struct btrfs_root *root = fs_info->dev_root; struct btrfs_root *root = fs_info->dev_root;
struct btrfs_key key; struct btrfs_key key;
struct extent_buffer *leaf; struct extent_buffer *leaf;
...@@ -304,28 +304,21 @@ static int calculate_emulated_zone_size(struct btrfs_fs_info *fs_info) ...@@ -304,28 +304,21 @@ static int calculate_emulated_zone_size(struct btrfs_fs_info *fs_info)
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) if (ret < 0)
goto out; return ret;
if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
ret = btrfs_next_leaf(root, path); ret = btrfs_next_leaf(root, path);
if (ret < 0) if (ret < 0)
goto out; return ret;
/* No dev extents at all? Not good */ /* No dev extents at all? Not good */
if (ret > 0) { if (ret > 0)
ret = -EUCLEAN; return -EUCLEAN;
goto out;
}
} }
leaf = path->nodes[0]; leaf = path->nodes[0];
dext = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_extent); dext = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_extent);
fs_info->zone_size = btrfs_dev_extent_length(leaf, dext); fs_info->zone_size = btrfs_dev_extent_length(leaf, dext);
ret = 0; return 0;
out:
btrfs_free_path(path);
return ret;
} }
int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info) int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info)
...@@ -1211,7 +1204,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache, ...@@ -1211,7 +1204,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache,
{ {
struct btrfs_fs_info *fs_info = cache->fs_info; struct btrfs_fs_info *fs_info = cache->fs_info;
struct btrfs_root *root; struct btrfs_root *root;
struct btrfs_path *path; BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key; struct btrfs_key key;
struct btrfs_key found_key; struct btrfs_key found_key;
int ret; int ret;
...@@ -1246,7 +1239,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache, ...@@ -1246,7 +1239,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache,
if (!ret) if (!ret)
ret = -EUCLEAN; ret = -EUCLEAN;
if (ret < 0) if (ret < 0)
goto out; return ret;
ret = btrfs_previous_extent_item(root, path, cache->start); ret = btrfs_previous_extent_item(root, path, cache->start);
if (ret) { if (ret) {
...@@ -1254,7 +1247,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache, ...@@ -1254,7 +1247,7 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache,
ret = 0; ret = 0;
*offset_ret = 0; *offset_ret = 0;
} }
goto out; return ret;
} }
btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);
...@@ -1266,15 +1259,10 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache, ...@@ -1266,15 +1259,10 @@ static int calculate_alloc_pointer(struct btrfs_block_group *cache,
if (!(found_key.objectid >= cache->start && if (!(found_key.objectid >= cache->start &&
found_key.objectid + length <= cache->start + cache->length)) { found_key.objectid + length <= cache->start + cache->length)) {
ret = -EUCLEAN; return -EUCLEAN;
goto out;
} }
*offset_ret = found_key.objectid + length - cache->start; *offset_ret = found_key.objectid + length - cache->start;
ret = 0; return 0;
out:
btrfs_free_path(path);
return ret;
} }
struct zone_info { struct zone_info {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment