Commit efac576c authored by David Sterba's avatar David Sterba
Browse files

btrfs: do trivial BTRFS_PATH_AUTO_FREE conversions



The most trivial pattern for the auto freeing when the variable is
declared with the macro and the final btrfs_free_path() is removed.
There are almost none goto -> return conversions and there's no other
function cleanup.

Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent bd06bce1
Loading
Loading
Loading
Loading
+7 −13
Original line number Diff line number Diff line
@@ -584,7 +584,7 @@ static int sample_block_group_extent_item(struct btrfs_caching_control *caching_
	struct btrfs_root *extent_root;
	u64 search_offset;
	u64 search_end = block_group->start + block_group->length;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct btrfs_key search_key;
	int ret = 0;

@@ -626,7 +626,6 @@ static int sample_block_group_extent_item(struct btrfs_caching_control *caching_

	lockdep_assert_held(&caching_ctl->mutex);
	lockdep_assert_held_read(&fs_info->commit_root_sem);
	btrfs_free_path(path);
	return ret;
}

@@ -2670,7 +2669,7 @@ static int insert_dev_extent(struct btrfs_trans_handle *trans,
{
	struct btrfs_fs_info *fs_info = device->fs_info;
	struct btrfs_root *root = fs_info->dev_root;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct btrfs_dev_extent *extent;
	struct extent_buffer *leaf;
	struct btrfs_key key;
@@ -2687,7 +2686,7 @@ static int insert_dev_extent(struct btrfs_trans_handle *trans,
	key.offset = start;
	ret = btrfs_insert_empty_item(trans, root, path, &key, sizeof(*extent));
	if (ret)
		goto out;
		return ret;

	leaf = path->nodes[0];
	extent = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_extent);
@@ -2695,10 +2694,8 @@ static int insert_dev_extent(struct btrfs_trans_handle *trans,
	btrfs_set_dev_extent_chunk_objectid(leaf, extent,
					    BTRFS_FIRST_CHUNK_TREE_OBJECTID);
	btrfs_set_dev_extent_chunk_offset(leaf, extent, chunk_offset);

	btrfs_set_dev_extent_length(leaf, extent, num_bytes);
out:
	btrfs_free_path(path);

	return ret;
}

@@ -3335,7 +3332,7 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans)
	struct btrfs_fs_info *fs_info = trans->fs_info;
	struct btrfs_block_group *cache, *tmp;
	struct btrfs_transaction *cur_trans = trans->transaction;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);

	if (list_empty(&cur_trans->dirty_bgs) ||
	    !btrfs_test_opt(fs_info, SPACE_CACHE))
@@ -3352,7 +3349,6 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans)
			cache_save_setup(cache, trans, path);
	}

	btrfs_free_path(path);
	return 0;
}

@@ -3375,7 +3371,7 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans)
	struct btrfs_transaction *cur_trans = trans->transaction;
	int ret = 0;
	int should_put;
	struct btrfs_path *path = NULL;
	BTRFS_PATH_AUTO_FREE(path);
	LIST_HEAD(dirty);
	struct list_head *io = &cur_trans->io_bgs;
	int loops = 0;
@@ -3530,7 +3526,6 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans)
		btrfs_cleanup_dirty_bgs(cur_trans, fs_info);
	}

	btrfs_free_path(path);
	return ret;
}

@@ -3541,7 +3536,7 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
	struct btrfs_transaction *cur_trans = trans->transaction;
	int ret = 0;
	int should_put;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct list_head *io = &cur_trans->io_bgs;

	path = btrfs_alloc_path();
@@ -3653,7 +3648,6 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
		btrfs_put_block_group(cache);
	}

	btrfs_free_path(path);
	return ret;
}

+1 −2
Original line number Diff line number Diff line
@@ -4306,7 +4306,7 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
		      u32 data_size)
{
	int ret = 0;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct extent_buffer *leaf;
	unsigned long ptr;

@@ -4320,7 +4320,6 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
		write_extent_buffer(leaf, data, ptr, data_size);
		btrfs_mark_buffer_dirty(trans, leaf);
	}
	btrfs_free_path(path);
	return ret;
}

+1 −2
Original line number Diff line number Diff line
@@ -1211,7 +1211,7 @@ int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
				     struct btrfs_inode *inode)
{
	struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct btrfs_block_rsv *block_rsv;
	int ret;

@@ -1238,7 +1238,6 @@ int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
	ret = __btrfs_commit_inode_delayed_items(trans, path, delayed_node);

	btrfs_release_delayed_node(delayed_node);
	btrfs_free_path(path);
	trans->block_rsv = block_rsv;

	return ret;
+1 −2
Original line number Diff line number Diff line
@@ -1087,13 +1087,12 @@ struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
					const struct btrfs_key *key)
{
	struct btrfs_root *root;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);

	path = btrfs_alloc_path();
	if (!path)
		return ERR_PTR(-ENOMEM);
	root = read_tree_root_path(tree_root, path, key);
	btrfs_free_path(path);

	return root;
}
+8 −17
Original line number Diff line number Diff line
@@ -70,9 +70,8 @@ static int block_group_bits(struct btrfs_block_group *cache, u64 bits)
int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len)
{
	struct btrfs_root *root = btrfs_extent_root(fs_info, start);
	int ret;
	struct btrfs_key key;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);

	path = btrfs_alloc_path();
	if (!path)
@@ -81,9 +80,7 @@ int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len)
	key.objectid = start;
	key.type = BTRFS_EXTENT_ITEM_KEY;
	key.offset = len;
	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
	btrfs_free_path(path);
	return ret;
	return btrfs_search_slot(NULL, root, &key, path, 0, 0);
}

/*
@@ -1487,7 +1484,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
				  struct btrfs_delayed_ref_node *node,
				  struct btrfs_delayed_extent_op *extent_op)
{
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct extent_buffer *leaf;
	struct btrfs_extent_item *item;
	struct btrfs_key key;
@@ -1508,7 +1505,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
					   node->parent, node->ref_root, owner,
					   offset, refs_to_add, extent_op);
	if ((ret < 0 && ret != -EAGAIN) || !ret)
		goto out;
		return ret;

	/*
	 * Ok we had -EAGAIN which means we didn't have space to insert and
@@ -1533,8 +1530,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,

	if (ret)
		btrfs_abort_transaction(trans, ret);
out:
	btrfs_free_path(path);

	return ret;
}

@@ -5465,7 +5461,7 @@ static int check_ref_exists(struct btrfs_trans_handle *trans,
{
	struct btrfs_delayed_ref_root *delayed_refs;
	struct btrfs_delayed_ref_head *head;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct btrfs_extent_inline_ref *iref;
	int ret;
	bool exists = false;
@@ -5482,7 +5478,6 @@ static int check_ref_exists(struct btrfs_trans_handle *trans,
		 * If we get 0 then we found our reference, return 1, else
		 * return the error if it's not -ENOENT;
		 */
		btrfs_free_path(path);
		return (ret < 0 ) ? ret : 1;
	}

@@ -5517,7 +5512,6 @@ static int check_ref_exists(struct btrfs_trans_handle *trans,
	mutex_unlock(&head->mutex);
out:
	spin_unlock(&delayed_refs->lock);
	btrfs_free_path(path);
	return exists ? 1 : 0;
}

@@ -6285,7 +6279,7 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
			struct extent_buffer *parent)
{
	struct btrfs_fs_info *fs_info = root->fs_info;
	struct btrfs_path *path;
	BTRFS_PATH_AUTO_FREE(path);
	struct walk_control *wc;
	int level;
	int parent_level;
@@ -6298,10 +6292,8 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
		return -ENOMEM;

	wc = kzalloc(sizeof(*wc), GFP_NOFS);
	if (!wc) {
		btrfs_free_path(path);
	if (!wc)
		return -ENOMEM;
	}

	btrfs_assert_tree_write_locked(parent);
	parent_level = btrfs_header_level(parent);
@@ -6338,7 +6330,6 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
	}

	kfree(wc);
	btrfs_free_path(path);
	return ret;
}

Loading