Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1125182ybl; Sat, 18 Jan 2020 19:23:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxbn888Hkoe85zWHfpIjkUAacK+8eAcaBXmwoly5xmRWAyFpY1xkAJFB7xmu6VyrahDEaA8 X-Received: by 2002:aca:3909:: with SMTP id g9mr8618633oia.118.1579404225033; Sat, 18 Jan 2020 19:23:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579404225; cv=none; d=google.com; s=arc-20160816; b=m7kun+RWXxTq95K+05ikNds7Ym3WWPYQgrgu/8Nf6hljEoCrsLLkGKTf5w83CmhNsf OfxlrYz0Rj9oUskzS+kaA/gdMRXWYqZ1NxhvQC4qZQ6ILxmShzQ/bXaFDGqolSAvEkCV ood0xrez+sztp43/ayNAqmS0hjddypcUOXWn00auJ+1fpVNZH13pK13X9x0CkokNlto8 vN7jWnpkNk9HERI1jYTtVIXYzOph4quJ3MbjXvsj7xb+rwIMq+fAqzYVMlkBnOEqfRWo RIXCl42mVfXuaWRbpU4p0RypDbWpKwmxuDc0CSYM2X3dfIWqYGUpQXFaBNgTl+AzqH5l c/kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=VqdrPU6g+6k21UKmaeUxfCU4TOZKVGGFFrpijTFXzL8=; b=ccLrfXTfeQCDbC4Fy8aPNnxvE6SiKHfwiIRrphBNwq0vP/Z5nm4SYbzQVcTNwhBxZE z1HA1UPVl3Pwv6fo1E+G4cjhNQcSXZbBe9j+jxKs4hGrxzZcrNZa+p/yXPi/G26Y6fKt 7rK6Bv+FXsSbBAKTEh3AJ4a+S53i0JkYqrjcuD/os0NmJrSszr88T396Nogt0jWTYasG sxa68W+39NWdrmNes0Ckp/NdErxmzEW8mLOqFZ+jYIpFAQ9HzScj1wbysjZMdE5yYY1h Y+FkvZrwORH13NGnjlK1gMF0JWOR8pgdcU26yOxLZdZeExsCX2pnzHml3RLbsTIyJbj4 9LGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23si17334900oto.205.2020.01.18.19.23.32; Sat, 18 Jan 2020 19:23:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726626AbgASDWk (ORCPT + 99 others); Sat, 18 Jan 2020 22:22:40 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:56860 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725497AbgASDWk (ORCPT ); Sat, 18 Jan 2020 22:22:40 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1it1A4-00BFcX-SW; Sun, 19 Jan 2020 03:22:11 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Aleksa Sarai , David Howells , Eric Biederman , Christian Brauner , Al Viro Subject: [PATCH 15/17] fold handle_mounts() into step_into() Date: Sun, 19 Jan 2020 03:17:27 +0000 Message-Id: <20200119031738.2681033-15-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200119031738.2681033-1-viro@ZenIV.linux.org.uk> References: <20200119031423.GV8904@ZenIV.linux.org.uk> <20200119031738.2681033-1-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro The following is true: * calls of handle_mounts() and step_into() are always paired in sequences like err = handle_mounts(nd, dentry, &path, &inode, &seq); if (unlikely(err < 0)) return err; err = step_into(nd, &path, flags, inode, seq); * in all such sequences path is uninitialized before and unused after this pair of calls * in all such sequences inode and seq are unused afterwards. So the call of handle_mounts() can be shifted inside step_into(), turning 'path' into a local variable in the combined function. Signed-off-by: Al Viro --- fs/namei.c | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 44634643475d..6c28b969f4d1 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1721,31 +1721,35 @@ enum {WALK_FOLLOW = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4}; * so we keep a cache of "no, this doesn't need follow_link" * for the common case. */ -static inline int step_into(struct nameidata *nd, struct path *path, - int flags, struct inode *inode, unsigned seq) +static int step_into(struct nameidata *nd, int flags, + struct dentry *dentry, struct inode *inode, unsigned seq) { + struct path path; + int err = handle_mounts(nd, dentry, &path, &inode, &seq); + + if (err < 0) + return err; if (!(flags & WALK_MORE) && nd->depth) put_link(nd); - if (likely(!d_is_symlink(path->dentry)) || + if (likely(!d_is_symlink(path.dentry)) || !(flags & WALK_FOLLOW || nd->flags & LOOKUP_FOLLOW) || flags & WALK_NOFOLLOW) { /* not a symlink or should not follow */ - path_to_nameidata(path, nd); + path_to_nameidata(&path, nd); nd->inode = inode; nd->seq = seq; return 0; } /* make sure that d_is_symlink above matches inode */ if (nd->flags & LOOKUP_RCU) { - if (read_seqcount_retry(&path->dentry->d_seq, seq)) + if (read_seqcount_retry(&path.dentry->d_seq, seq)) return -ECHILD; } - return pick_link(nd, path, inode, seq); + return pick_link(nd, &path, inode, seq); } static int walk_component(struct nameidata *nd, int flags) { - struct path path; struct dentry *dentry; struct inode *inode; unsigned seq; @@ -1769,11 +1773,7 @@ static int walk_component(struct nameidata *nd, int flags) if (IS_ERR(dentry)) return PTR_ERR(dentry); } - - err = handle_mounts(nd, dentry, &path, &inode, &seq); - if (unlikely(err < 0)) - return err; - return step_into(nd, &path, flags, inode, seq); + return step_into(nd, flags, dentry, inode, seq); } /* @@ -2222,17 +2222,10 @@ static inline int lookup_last(struct nameidata *nd) static int handle_lookup_down(struct nameidata *nd) { - struct path path; - struct inode *inode = nd->inode; - unsigned seq = nd->seq; - int err; - if (!(nd->flags & LOOKUP_RCU)) dget(nd->path.dentry); - err = handle_mounts(nd, nd->path.dentry, &path, &inode, &seq); - if (unlikely(err < 0)) - return err; - return step_into(nd, &path, WALK_NOFOLLOW, inode, seq); + return step_into(nd, WALK_NOFOLLOW, + nd->path.dentry, nd->inode, nd->seq); } /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ @@ -3149,7 +3142,6 @@ static int do_last(struct nameidata *nd, int acc_mode = op->acc_mode; unsigned seq; struct inode *inode; - struct path path; struct dentry *dentry; int error; @@ -3247,10 +3239,7 @@ static int do_last(struct nameidata *nd, } finish_lookup: - error = handle_mounts(nd, dentry, &path, &inode, &seq); - if (unlikely(error < 0)) - return error; - error = step_into(nd, &path, 0, inode, seq); + error = step_into(nd, 0, dentry, inode, seq); if (unlikely(error)) return error; -- 2.20.1