Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp410119pxu; Tue, 1 Dec 2020 14:34:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzoIwuBCM2bHA10VpBFGW73Ik/9fFmHZ7R2ytGWOWbD7nx6lQaUh8DoI3n4MQqjtMG2qGg X-Received: by 2002:a17:906:7f10:: with SMTP id d16mr5280972ejr.104.1606862079222; Tue, 01 Dec 2020 14:34:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606862079; cv=none; d=google.com; s=arc-20160816; b=O/ME7mGugX0Jh0NUulHuY9D2s010ceqZojRD10evwhWlXHfZIESLsCrAfYU47TxOHr HBAtQWgOkr/n8wTZXAYFn0uausHqQi+O4+Dia04MrTvYniyQvqTarsVjVTzn5Dtq39QV rjIQ/LItxUQvjPheDt4yBHDeAGBEi/zNxFCOxgKEm6cBrzwP6jDAswnUHwsHftJfbShe fzGNUwOfJA/6J6TNKqo2/UNKPBmL82ofFjgRM266adW8ESc17V4o8nWcUJzBRT0oaHra g7JXOsp35wSafvcgRfUwBdNtOjXvv4LPOWhI8Vx5ed9qL3smk58Do91Zb/ImGmvUo/yT BGlA== 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=u+kFjno/6pyO1USPda30/zXamWh3xre6jl5spBqPtuM=; b=0whouFuNjmNqCJ1XadArfwSo0KUT04/Bcbbke1koYSN4XNhEQbVeAcm/JJApkdmHXL zcAHRGau775vaDT3mnAZq0zUcYLqOYT6Ww9wOuOa+8LoTLudek4VPOSWWPhxbVX4yGsK 8vqGIxRQyZ71P5qkYmsYBbsA1v1YP/viDY7osgyV1oStNnzUvdown9fensLWA99mHevG +rzECu1BUGvzaN3BP9uU1o07IFklCp8E3DDn28xD8/z4yakKAbBK9UuYSTZsMOrYXtik 0wtymQdIkd826f9/MaQhnH1ATJ9dIt2Y6Z3B9go3+qUdJ1wEzs6UQ8K/16T9Hh2Ypq0C 68bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UhINjmCB; 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 p1si840174ejw.42.2020.12.01.14.34.16; Tue, 01 Dec 2020 14:34:39 -0800 (PST) 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=UhINjmCB; 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 S2391195AbgLAJaK (ORCPT + 99 others); Tue, 1 Dec 2020 04:30:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:34104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387951AbgLAI6b (ORCPT ); Tue, 1 Dec 2020 03:58:31 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 91A522222C; Tue, 1 Dec 2020 08:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813070; bh=SBUTAK6tLgiSZKsOhoZXkz1FRmay8B6GvjFtemMGAKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UhINjmCBxHIx0zK25otwsItqK+4Yq9eZ9blOf/1iUSUzV97OZVeLjaO6Wbpy9VWUv PQteuZw2q8eDzhe5Vv/wvL9TFhjj/690idHb7SuKD4ysO1Bes7d6ZryE+rkeAatcqF buYPXD8q2FjHTDnHjXzRHf5kqpQjdjO+uxlrmiA4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Su Yue , David Sterba , Sudip Mukherjee Subject: [PATCH 4.14 07/50] btrfs: adjust return values of btrfs_inode_by_name Date: Tue, 1 Dec 2020 09:53:06 +0100 Message-Id: <20201201084645.707259089@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084644.803812112@linuxfoundation.org> References: <20201201084644.803812112@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: Su Yue commit 005d67127fa9dfb3382f2c9e918feed7a243a7fe upstream Previously, btrfs_inode_by_name() returned 0 which left caller to check objectid of location even location if the type was invalid. Let btrfs_inode_by_name() return -EUCLEAN if a corrupted location of a dir entry is found. Removal of label out_err also simplifies the function. Signed-off-by: Su Yue Reviewed-by: David Sterba [ drop unlikely ] Signed-off-by: David Sterba Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5585,7 +5585,8 @@ no_delete: /* * this returns the key found in the dir entry in the location pointer. - * If no dir entries were found, location->objectid is 0. + * If no dir entries were found, returns -ENOENT. + * If found a corrupted location in dir entry, returns -EUCLEAN. */ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry, struct btrfs_key *location) @@ -5603,27 +5604,27 @@ static int btrfs_inode_by_name(struct in di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(BTRFS_I(dir)), name, namelen, 0); - if (IS_ERR(di)) + if (!di) { + ret = -ENOENT; + goto out; + } + if (IS_ERR(di)) { ret = PTR_ERR(di); - - if (IS_ERR_OR_NULL(di)) - goto out_err; + goto out; + } btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); if (location->type != BTRFS_INODE_ITEM_KEY && location->type != BTRFS_ROOT_ITEM_KEY) { + ret = -EUCLEAN; btrfs_warn(root->fs_info, "%s gets something invalid in DIR_ITEM (name %s, directory ino %llu, location(%llu %u %llu))", __func__, name, btrfs_ino(BTRFS_I(dir)), location->objectid, location->type, location->offset); - goto out_err; } out: btrfs_free_path(path); return ret; -out_err: - location->objectid = 0; - goto out; } /* @@ -5924,9 +5925,6 @@ struct inode *btrfs_lookup_dentry(struct if (ret < 0) return ERR_PTR(ret); - if (location.objectid == 0) - return ERR_PTR(-ENOENT); - if (location.type == BTRFS_INODE_ITEM_KEY) { inode = btrfs_iget(dir->i_sb, &location, root, NULL); return inode;