On Thu, Mar 8, 2018 at 2:33 PM, David Sterba <dste...@suse.com> wrote: > 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.
Nop, the allocation must be made before calling tree_mod_dont_log(), as that function acquires a write lock. That's why there's a call to tree_mod_need_log() before the allocation and a call to tree_mod_dont_log() after (they do the same checks). > > 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 -- Filipe David Manana, “Whether you think you can, or you think you can't — you're right.” -- 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