Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4325383pxj; Tue, 8 Jun 2021 11:32:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztsSSK11GJWS4ov1ntrbYfigZ2FMPJANnwmA2e8XMsjqT78PzlQ1qSrXawLF35q+8B6oFo X-Received: by 2002:a17:907:9487:: with SMTP id dm7mr17444903ejc.349.1623177163683; Tue, 08 Jun 2021 11:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623177163; cv=none; d=google.com; s=arc-20160816; b=yjflFN/OAc2paMVh/rhxaB+BQ8fMud4nNXeGz/sNYi6UMyqq1O1TVGXQrKttorAijv 1UJtfWVHkf7r6+6Hzaq0dKmjDT9S3UfJIDQpmYTjBl/NTCQbbXRA+EGMXZHSKG4/Z38e 0ETEeUzHX2XdxZYVUDHubKWIDAWjhVzhRGMT6scKAXBt9OgTkvLlo8sayLCCLJd3y/Jq QrTIah5/SilPyRolozM8JGh6jbewjeau9QftjL8IqRkBBZgwizBfjfgbprXbWKEZBhZa c6xv0ASG7esjGc2rbpsPc/Y3YAgqbn3n9kC93bBnXnA8RgeNCncChb1SfyjLy6N+X9As zTmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IraPMGfaJ39eZdLITYH4QlTPmxgfu5PvYG3Zt8YVyD8=; b=pf6F+xceXrNnUr5J+PbRpHArR+fHLTipWLlPqegqQAKLCaZKE1iBZ+AykvGg8/1/Jv B4eEkfF+X1YXwJ9t7grFrocAZlPS7BJsfgdcRaDjULuEfxHSZ84OQKNVf9XUszaTscV0 pQRJzl1ADElqEVjD0u/vRhFZDMhSNghUnXrGgXWAqWhm64fcupjNpYW3eyOv3+D+dqAI Vf1JJtR6aBOHiDpV2GKYiYAQPLRxPMGg/pmyaQnL6NLj/hstY8K440x0qC1E2LOTVnB+ UvebFv1Q87kvHWQCGfLEV1Z/jpaJHQAKoahrkuYH/vyIMDPRiYADVYSbIoyATyjCw6RP gRcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yQXrtd97; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z12si342384ejl.649.2021.06.08.11.32.19; Tue, 08 Jun 2021 11:32:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yQXrtd97; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234023AbhFHScR (ORCPT + 99 others); Tue, 8 Jun 2021 14:32:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:56318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234155AbhFHSbe (ORCPT ); Tue, 8 Jun 2021 14:31:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C5924613C5; Tue, 8 Jun 2021 18:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623176967; bh=uP5csr2qifp5imC+lku80earoP3BQ3lVsLP9LVzkjw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yQXrtd97Jvi/c5ClUA9qcEvbv0TzVx4SuV9ef1QPFZlL1a4SuBeXAiWwahQYN8Whl 1gAHuMaAun/Zk2w6RLmRbiXnIeMf2bO9MTgggDe2Otn+RJhZzsxkvcoX+6cBfr6pSn ACVk52NafUWwTtv6MX3G5oxl/52Wdv5t+i/4z5u8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 4.4 20/23] btrfs: fixup error handling in fixup_inode_link_counts Date: Tue, 8 Jun 2021 20:27:12 +0200 Message-Id: <20210608175927.187390732@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175926.524658689@linuxfoundation.org> References: <20210608175926.524658689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik commit 011b28acf940eb61c000059dd9e2cfcbf52ed96b upstream. This function has the following pattern while (1) { ret = whatever(); if (ret) goto out; } ret = 0 out: return ret; However several places in this while loop we simply break; when there's a problem, thus clearing the return value, and in one case we do a return -EIO, and leak the memory for the path. Fix this by re-arranging the loop to deal with ret == 1 coming from btrfs_search_slot, and then simply delete the ret = 0; out: bit so everybody can break if there is an error, which will allow for proper error handling to occur. CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -1511,6 +1511,7 @@ static noinline int fixup_inode_link_cou break; if (ret == 1) { + ret = 0; if (path->slots[0] == 0) break; path->slots[0]--; @@ -1523,17 +1524,19 @@ static noinline int fixup_inode_link_cou ret = btrfs_del_item(trans, root, path); if (ret) - goto out; + break; btrfs_release_path(path); inode = read_one_inode(root, key.offset); - if (!inode) - return -EIO; + if (!inode) { + ret = -EIO; + break; + } ret = fixup_inode_link_count(trans, root, inode); iput(inode); if (ret) - goto out; + break; /* * fixup on a directory may create new entries, @@ -1542,8 +1545,6 @@ static noinline int fixup_inode_link_cou */ key.offset = (u64)-1; } - ret = 0; -out: btrfs_release_path(path); return ret; }