Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4340156pxj; Tue, 8 Jun 2021 11:55:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGIgfXiJNJi5mcCtsRVYN9iysCrWZqjqp7rX3RUm7FbGhb04tGtlt+xNoAL5owhQKgg6vZ X-Received: by 2002:a17:906:1444:: with SMTP id q4mr25253319ejc.459.1623178530429; Tue, 08 Jun 2021 11:55:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623178530; cv=none; d=google.com; s=arc-20160816; b=psfbaWpBxSOqQL8eNylr+TY22bOp3zY2qI6Q+/pi4ySTrmdMAB20PBdUBBLm3/Ox6z 0scSh8HI5Ncw5kvOoPQgkkjDSjrWz6O9B6TcWOomfS+A8nW5EdfBBg93WzsxPLMThugZ Z4Mg9laUmCT+p8Q6BK3TXslvMxU+7/TCDvSAQi2oa7xwpV96HE8gngSwkI/mUmhIYyrV jVozqtmFDrFCPn3/a7s4zwFs2iMva3PyFgHbS5PysPL0kL3+D9fKdKZrH/dB8653OjCc zYqAkq7Hn12IqxQ0kVEn0L8sQBkNCH402I/Ph9aVpoKPzGgNf9/dVi9/bPmpAb09KruB Hdgg== 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=1XSJDupuXs6pNSOXUU3M+uCxqQlybW16H+cX0QF4dCA=; b=Bfb0/24Ji3YSZ0Pijco5i4kBFJcdEi7PiMkvoNXPyNge50aFonXeqaw9K2nxqaLC0m BlshPGc+JjiKT/eBaaT+byhMMmCSpBdF9OXX2doOPQJ4gRPYI8plC7V/tlemk0RGwNXh gKmYw6PWRGU2f5HycBbwddQjgLQs9lV9tCFCb5mIb1WdJI2SeVKL/xqSZeRIPJXlHlzp VgsiuH1/9iJ0wsVkcRVoua8C0lBz53l9+kR2PsIM63n9QCmVNMKXCvS8gAjO4+F1NapJ K2t9gZytMrtnpdilDy0v+W1iQvjA6c5GC5OLlnhpqAfVgRCp+8IZmdzyONxWDYO8l5GX 33yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G1xdUylC; 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 b16si382146ede.389.2021.06.08.11.55.06; Tue, 08 Jun 2021 11:55: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=G1xdUylC; 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 S235369AbhFHSw4 (ORCPT + 99 others); Tue, 8 Jun 2021 14:52:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:42390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235524AbhFHSrA (ORCPT ); Tue, 8 Jun 2021 14:47:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04F726145A; Tue, 8 Jun 2021 18:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177470; bh=ZslwLgAJrBNARuZSGZ4T3vO5PKHkdKQu93YpIlOCH94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G1xdUylCYZaguhCom71UHnmJFKIDdeVGk/yPE5B1LsUpKhzKwVowq0FeEFiD392Kp q5bCPXqUZI2wBPDS3MTW6F3Kfcoz1iB0Yj09aqJSmIQ8/UnJkXZIhZqtznlOO8FsY2 KSGuw4AcHVxf80Gqo3q7PgOYc+Tk23aX52EjmE04= 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.4 62/78] btrfs: fixup error handling in fixup_inode_link_counts Date: Tue, 8 Jun 2021 20:27:31 +0200 Message-Id: <20210608175937.368738145@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@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 @@ -1775,6 +1775,7 @@ static noinline int fixup_inode_link_cou break; if (ret == 1) { + ret = 0; if (path->slots[0] == 0) break; path->slots[0]--; @@ -1787,17 +1788,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, @@ -1806,8 +1809,6 @@ static noinline int fixup_inode_link_cou */ key.offset = (u64)-1; } - ret = 0; -out: btrfs_release_path(path); return ret; }