The allocation of tree_mod_elem can be delayed after tree_mod_dont_log. In case it causes the function to return, the allocation would be redundant. Otherwise it could cause unnecessary failure if there's not enough memory.
Signed-off-by: David Sterba <dste...@suse.com> --- fs/btrfs/ctree.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 30950439731e..da6e2c3ca2d0 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -521,15 +521,13 @@ static noinline int tree_mod_log_insert_key(struct extent_buffer *eb, int slot, if (!tree_mod_need_log(eb->fs_info, eb)) return 0; + if (tree_mod_dont_log(eb->fs_info, eb)) + return 0; + tm = alloc_tree_mod_elem(eb, slot, op, flags); if (!tm) return -ENOMEM; - if (tree_mod_dont_log(eb->fs_info, eb)) { - kfree(tm); - return 0; - } - ret = __tree_mod_log_insert(eb->fs_info, tm); write_unlock(&eb->fs_info->tree_mod_log_lock); if (ret) -- 2.16.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html