Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4853852pxj; Wed, 9 Jun 2021 03:36:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzza4c7f19+26Rbr4bz4fl1PVrCsi+806BwUfUyHfFOeSKWMJDZyT8F1YZNowmoUcLI4+J1 X-Received: by 2002:a17:907:9047:: with SMTP id az7mr27732583ejc.4.1623235005357; Wed, 09 Jun 2021 03:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623235005; cv=none; d=google.com; s=arc-20160816; b=zAwN8dl/vTkQg++zbLbpDrhGsga6sXhqLAYgKhkL23MEQ5Si6zAG4wPvGTiruJ7Tn2 RJfEbKnNvyyTvh76uR3ebayUL5d4tBjf9O9+9vFoUWFPsuFeB33PN12wNbmaAMfs7kK7 fq0yEEQ0xL9poFTENPCXFcslgnIX/1MUnf6tUBl2QPudvwtjNG12LQq5khbsk26maIm4 aSbTnZ9E6i91HsG0NPGe9wLcNto1/w3ZINXrKxLUETcMDnF+yRxbS47La5gfWXTwEKXt gOGQPT0vBw8fnEujPlmHxcjmvZsKFJIMYzpMfZwB85kfNC30GdumId4+rAmPCD7/ly3T vUyA== 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=mfgywBm7m/6QvK46mQlIsdy4GYl/5xnKss09AcXjMJE=; b=ZSaN2ZcE0BNs7KI6bNiIFi4s/7cNfihjULbF10YGfxaw1XlMQh+5qYApO+5p4CBiiy 9lXskMuZ8XuUy3Twdqki3jfAjsWgA0iuS37jn9Xf32XNdodme3NFWg05hgJNQ654xvZe nZbxM/gY/xq62GRGQlD5cBCpJ4n0qIS3HCS/b+ZyN8pmcHsKggfNUrb8f6t2qbw5iMy0 Apyxf0UZ33Teq9MMUQN2t/gDibzNuNtERjEp7y1EJgJmxxzkXUV59bdR+wH2CMBwZwO4 MEL6lVkTk5C6i8HX7yK7NtqDW15LdgwBKKElTbahH46Ut7eRalzGJlBH2VVgepVXwre1 Enpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mt1Tbwru; 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 c13si2066709ejm.484.2021.06.09.03.36.21; Wed, 09 Jun 2021 03:36:45 -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=mt1Tbwru; 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 S238070AbhFHTKu (ORCPT + 99 others); Tue, 8 Jun 2021 15:10:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:39970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237588AbhFHTA6 (ORCPT ); Tue, 8 Jun 2021 15:00:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CA53261874; Tue, 8 Jun 2021 18:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177846; bh=sjLsm0m61TxduIh14j8qvimTjjhrJSGvg02VhThmiRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mt1TbwruA+CVuHOYkLaBH+euS7kic/jlqQ5NFOM/RXV5fKzg9Wj03OwJXECenBdjY 93JEXIio4F0iOsjMvybJyt1rxJMcWxnhB4l0lRFuEu1KG4c9POjjyMG9kvOKVgeLP8 ie/vuAnWKsJSoyAvrqNQnd2DVV9BGPllFLIuWWR8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 5.10 122/137] btrfs: fixup error handling in fixup_inode_link_counts Date: Tue, 8 Jun 2021 20:27:42 +0200 Message-Id: <20210608175946.504062873@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175942.377073879@linuxfoundation.org> References: <20210608175942.377073879@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 @@ -1752,6 +1752,7 @@ static noinline int fixup_inode_link_cou break; if (ret == 1) { + ret = 0; if (path->slots[0] == 0) break; path->slots[0]--; @@ -1764,17 +1765,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, @@ -1783,8 +1786,6 @@ static noinline int fixup_inode_link_cou */ key.offset = (u64)-1; } - ret = 0; -out: btrfs_release_path(path); return ret; }