Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4823081pxj; Wed, 9 Jun 2021 02:44:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRhn7nKT6XexystEJ3e+Ek8d6eu0bu5qP+p9VC4isD5m2ZtPhW2QjJyNyKMoJyj1LL5JZ/ X-Received: by 2002:a5d:948f:: with SMTP id v15mr22652997ioj.28.1623231863824; Wed, 09 Jun 2021 02:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623231863; cv=none; d=google.com; s=arc-20160816; b=D/yLCubrntyUx09t7Rx4hRRRtI7hZBc8OWqbWvps32WJezCOOCvRdlmD2i6JL3JbgO yY56LaUWlrN9kFOrPcJZDG2+pEnB6osh4S1IGvO0fHiOCuu9tffv2We2jTYNJVPaszxO kDL2JbnS3LLL6O+uDeyXL+VZWbwNXE8xoV6Tpc38E9k9SFS3U368sGowOuHRBETKSRsK xux1QtH9dJUwE7kOds9xQ3FMfYAmTkBQnh0qC8jdzwVP4NeM18yJX/SMkW9HGrxEz/Gh E2ExRjf8iluG76k2hgWli4toNJVZH3lquXTnuf4cBM5F3772P4SOuOA37T87itr8sIAr DTwg== 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=rBxCam7UcQFyDdr0wIvScMY2AkwcPRjsJdH+DxC5rbw=; b=qQWprAmGx3KtJjLuZj8DPajrSj72+kUPozCkI8yxZKLuUFcQYYrn9nZ0dpJQPsIVWb 4iZsASsGnqDoO5iSwVcjY5itp88c22EX9HOxtfLd2UrJ7K8bzg6Ft8oy4AfzbYrc+O+R L6+D4GHRyjBjuIHhMZnnQXyURI4bprGfQ4aiCse9KaM+hUpbjOerCwrwqD+pxLb6Ys2g fng/uijqMx7b8Ml62atwUYT8is1W5qMRmXbyc3OJYYhHgOtbew1SPDHWjSnooC5SDMcp Vr9Ak1AIPid6Wpv8TnKTjP6zu/S9wh0XMqsO2NcBfEKTH+49nB+PTLDSDmPs7bJdV6sK HCXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A3v+9okr; 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 g12si508563ila.95.2021.06.09.02.44.11; Wed, 09 Jun 2021 02:44:23 -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=A3v+9okr; 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 S235261AbhFHSmS (ORCPT + 99 others); Tue, 8 Jun 2021 14:42:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:35816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235219AbhFHSjV (ORCPT ); Tue, 8 Jun 2021 14:39:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5D462613CC; Tue, 8 Jun 2021 18:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177242; bh=2APocfDjz0qG4uOXuqNChhRUgIpmZ5ufesWxVRnU2Z8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A3v+9okr/77fhCVnTqMA866O/6a58R0HTUi8qhE61T4vCXvV5Wnj7KKAICp7s+6Rq Dc5xqBQavo4m1/IwD5VGaxhDrdETeP/r+VBr6kpvcYelF3dOEs1svv9QaSnZPklfsl YnqikBbJhS11y5U5AK4pa3l8nk9/a4XY7ew5fNvY= 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.19 38/58] btrfs: fixup error handling in fixup_inode_link_counts Date: Tue, 8 Jun 2021 20:27:19 +0200 Message-Id: <20210608175933.529291084@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175932.263480586@linuxfoundation.org> References: <20210608175932.263480586@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 @@ -1699,6 +1699,7 @@ static noinline int fixup_inode_link_cou break; if (ret == 1) { + ret = 0; if (path->slots[0] == 0) break; path->slots[0]--; @@ -1711,17 +1712,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, @@ -1730,8 +1733,6 @@ static noinline int fixup_inode_link_cou */ key.offset = (u64)-1; } - ret = 0; -out: btrfs_release_path(path); return ret; }