Skip to content

Commit

Permalink
btrfs: btrfs_truncate_free_space_cache always allocates path
Browse files Browse the repository at this point in the history
btrfs_truncate_free_space_cache always allocates a btrfs_path structure
but only uses it when the caller passes a block group.  Let's move the
allocation and free into the conditional.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Jeff Mahoney authored and David Sterba committed Feb 17, 2017
1 parent 77ab86b commit 21e75ff
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fs/btrfs/free-space-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
{
struct btrfs_root *root = BTRFS_I(inode)->root;
int ret = 0;
struct btrfs_path *path = btrfs_alloc_path();
bool locked = false;

if (!path) {
ret = -ENOMEM;
goto fail;
}

if (block_group) {
struct btrfs_path *path = btrfs_alloc_path();

if (!path) {
ret = -ENOMEM;
goto fail;
}
locked = true;
mutex_lock(&trans->transaction->cache_write_mutex);
if (!list_empty(&block_group->io_list)) {
Expand All @@ -257,8 +257,8 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
spin_lock(&block_group->lock);
block_group->disk_cache_state = BTRFS_DC_CLEAR;
spin_unlock(&block_group->lock);
btrfs_free_path(path);
}
btrfs_free_path(path);

btrfs_i_size_write(inode, 0);
truncate_pagecache(inode, 0);
Expand Down

0 comments on commit 21e75ff

Please sign in to comment.