From patchwork Thu Mar 8 14:33:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 10268189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 90E996016D for ; Thu, 8 Mar 2018 14:36:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 827B029882 for ; Thu, 8 Mar 2018 14:36:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7689D2995D; Thu, 8 Mar 2018 14:36:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00D0729882 for ; Thu, 8 Mar 2018 14:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755656AbeCHOgK (ORCPT ); Thu, 8 Mar 2018 09:36:10 -0500 Received: from mx2.suse.de ([195.135.220.15]:56844 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755565AbeCHOgI (ORCPT ); Thu, 8 Mar 2018 09:36:08 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6338DAE22 for ; Thu, 8 Mar 2018 14:36:07 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 5300CDA907; Thu, 8 Mar 2018 15:33:47 +0100 (CET) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 18/22] btrfs: move allocation after simple tests in tree_mod_log_insert_key Date: Thu, 8 Mar 2018 15:33:47 +0100 Message-Id: <0792f4331c42c57426d02f897bc68b7c7820219a.1520518876.git.dsterba@suse.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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)