From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93845C43387 for ; Tue, 8 Jan 2019 19:33:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 57BA920827 for ; Tue, 8 Jan 2019 19:33:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546976000; bh=y9poZcvpZiIiGWg94evkl8KnA5COysPDKq/WTrmkBK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PWKGBgnzBXYL76ZBB17sPoLrMRchI9fOMRGl/uS3KvbMJ97TyKnUzMczSFSIorV/G p5kWYLr0cDTT2DDD61ICsZAvFRFdJnAD3G+mRj6+deZwrwNWUMiPo4ZAgn9oQRIaHX RDYH0Lsv4kwHWrzu8hJPD4zKpTEXbZfuuRmBs0vQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731656AbfAHTdT (ORCPT ); Tue, 8 Jan 2019 14:33:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:42046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731610AbfAHTdO (ORCPT ); Tue, 8 Jan 2019 14:33:14 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5DD2B205C9; Tue, 8 Jan 2019 19:33:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975994; bh=y9poZcvpZiIiGWg94evkl8KnA5COysPDKq/WTrmkBK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MypMykxBXEjiAVjQF3cD9dW/UuiIIWSS9j6YfvxCsPCNPpVAOWbTd6SwnEaH0PbJe QYS4klMeoACmUzgu5AJkshHm7dAjQzRCmCyHfibToVNtaSXgXQSUrr6uOSejbdgOH0 iCdr4HFP8LdPQG/L6XbKLBDznKh7bLRx/sVlNg1E= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Johannes Thumshirn , David Sterba , Sasha Levin , linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 32/53] btrfs: improve error handling of btrfs_add_link Date: Tue, 8 Jan 2019 14:32:00 -0500 Message-Id: <20190108193222.123316-32-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108193222.123316-1-sashal@kernel.org> References: <20190108193222.123316-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Thumshirn [ Upstream commit 1690dd41e0cb1dade80850ed8a3eb0121b96d22f ] In the error handling block, err holds the return value of either btrfs_del_root_ref() or btrfs_del_inode_ref() but it hasn't been checked since it's introduction with commit fe66a05a0679 (Btrfs: improve error handling for btrfs_insert_dir_item callers) in 2012. If the error handling in the error handling fails, there's not much left to do and the abort either happened earlier in the callees or is necessary here. So if one of btrfs_del_root_ref() or btrfs_del_inode_ref() failed, abort the transaction, but still return the original code of the failure stored in 'ret' as this will be reported to the user. Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 1c340d6c8568..997ed98ce8cb 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6582,14 +6582,19 @@ int btrfs_add_link(struct btrfs_trans_handle *trans, err = btrfs_del_root_ref(trans, fs_info, key.objectid, root->root_key.objectid, parent_ino, &local_index, name, name_len); - + if (err) + btrfs_abort_transaction(trans, err); } else if (add_backref) { u64 local_index; int err; err = btrfs_del_inode_ref(trans, root, name, name_len, ino, parent_ino, &local_index); + if (err) + btrfs_abort_transaction(trans, err); } + + /* Return the original error code */ return ret; } -- 2.19.1