Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4819819pxj; Wed, 9 Jun 2021 02:38:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDvqh/FOnd5hlLiml3XA1N8goTuVjiAuOb5fwDK0hV1kadV3fqSYGSZfqlFmqfiQ+Bv0UY X-Received: by 2002:a92:dc49:: with SMTP id x9mr4346431ilq.144.1623231510402; Wed, 09 Jun 2021 02:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623231510; cv=none; d=google.com; s=arc-20160816; b=C8+ZdAZ7oofAfqgMu8ZxjeOgo8YToVuOn3NN6Acty0Zpx7wEFAz4NsFRSkPW00QOX+ Hahq0mZRrXk+udIDa5A+P/6bkWgMT6WGppwTotSw49E+uJxihhSwvdlEcoaqfLtch/yM swPsg5j4fyDin6JrOFOJKdK5/xp9UF6RWvAp1cY0rtZxOF1ZSzdljuj48yKwl7cGuP7t Ysprn0w8QhG1KyKl7ULHiVmwKtiBxmxkmH8Q4Vocy2aT3NOS4bMfzMrlHqyUZjDGoG+C UHFPGoFX5D53FDpRqK35tYhDbhN37Zt3VszUzEvX1qBXUzaXLswN9dsryjRxkyYT1TIF c4wg== 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=Hpo6e2MBbEW7FKIrdrpoWtJal4qJDiAXxp4Km0tCh4w=; b=tIS/URDcIvBuhRQApsD7UFzRMNY+vHgJGtOZKkT3R0UfR/u7dFBQd5hz+p1XxhFfN0 jsyrOU6+zqWTV5UZ4hTF7t+pTnKbNKMrBytG9qTUUCPfbpAlatVT5JDF0Uap+4nTIdk/ r2bvhL4QNv5oiXJih+00N8nGCiBMl3hvOkzaSyvXSAeGkd+trYQ1MjurfRgOATBpOC1V F1TjrKSJg9h1p2ZTauBw95M965NBegB3MiU+RYyE0a8TP5sLh9JBra6+RfpJKPCaOdkI S8R62nRuyp4+/1Bj9J0bSaVmu4vNgM8RHfBC90Q2GsZyAUwaee+ltuYhy7UCjROCXocL olxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CKvHiH52; 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 x9si2552006ilo.119.2021.06.09.02.38.18; Wed, 09 Jun 2021 02:38:30 -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=CKvHiH52; 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 S234659AbhFHSfd (ORCPT + 99 others); Tue, 8 Jun 2021 14:35:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:57560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234629AbhFHSdp (ORCPT ); Tue, 8 Jun 2021 14:33:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3C51F613BE; Tue, 8 Jun 2021 18:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177080; bh=Q+B/uVpWs0oT3LLbwGd7o7GS1/qIOetT+U4smrP+HTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CKvHiH52521BxhafqmKsHcOUePjDK651W++zGsc2jDj0eX9zawzO9nmJy80pS6qeA wxsUzxmLIvwfC3lrKJv7ncCe8JVxY3tDRs/eW6zEMtIKPQxkXKTpZ3Ex5h86ObhHa2 w8elkg3QtZQWJXEkzkkZHzKqjlaSQtkgI9+zCFDA= 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.14 25/47] btrfs: fixup error handling in fixup_inode_link_counts Date: Tue, 8 Jun 2021 20:27:08 +0200 Message-Id: <20210608175931.305692212@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175930.477274100@linuxfoundation.org> References: <20210608175930.477274100@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 @@ -1558,6 +1558,7 @@ static noinline int fixup_inode_link_cou break; if (ret == 1) { + ret = 0; if (path->slots[0] == 0) break; path->slots[0]--; @@ -1570,17 +1571,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, @@ -1589,8 +1592,6 @@ static noinline int fixup_inode_link_cou */ key.offset = (u64)-1; } - ret = 0; -out: btrfs_release_path(path); return ret; }