From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754963AbbDTSOf (ORCPT ); Mon, 20 Apr 2015 14:14:35 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:34777 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754271AbbDTSNM (ORCPT ); Mon, 20 Apr 2015 14:13:12 -0400 From: Al Viro To: Linus Torvalds Cc: Neil Brown , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 21/24] namei: regularize use of put_link() and follow_link(), trim arguments Date: Mon, 20 Apr 2015 19:13:05 +0100 Message-Id: <1429553588-24764-21-git-send-email-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <20150420181222.GK889@ZenIV.linux.org.uk> References: <20150420181222.GK889@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro don't bother with separate variables for link and cookie in trailing symlink loops; use nd->stack[0] for that. That makes *all* callers of put_link() (and follow_link()) operate on nd->stack[nd->depth].link and nd->stack[nd->depth].cookie. Trim the argument lists. Signed-off-by: Al Viro --- fs/namei.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 1c967d1..a8d6751 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -752,12 +752,14 @@ static inline char *nd_get_link(struct nameidata *nd) return nd->stack[nd->depth].body; } -static inline void put_link(struct nameidata *nd, struct path *link, void *cookie) +static inline void put_link(struct nameidata *nd) { - struct inode *inode = link->dentry->d_inode; + struct saved *last = nd->stack + nd->depth; + struct inode *inode = last->link.dentry->d_inode; if (inode->i_op->put_link) - inode->i_op->put_link(link->dentry, nd_get_link(nd), cookie); - path_put(link); + inode->i_op->put_link(last->link.dentry, last->body, + last->cookie); + path_put(&last->link); } int sysctl_protected_symlinks __read_mostly = 0; @@ -925,14 +927,16 @@ out: return res; } -static int follow_link(struct path *link, struct nameidata *nd, void **p) +static int follow_link(struct nameidata *nd, struct path *link) { char *s; int error = may_follow_link(link, nd); + struct saved *last = nd->stack + nd->depth; if (unlikely(error)) return error; nd->flags |= LOOKUP_PARENT; - s = get_link(link, nd, p); + last->link = *link; + s = get_link(&last->link, nd, &last->cookie); if (unlikely(IS_ERR(s))) return PTR_ERR(s); if (unlikely(!s)) @@ -948,7 +952,7 @@ static int follow_link(struct path *link, struct nameidata *nd, void **p) nd->inode = nd->path.dentry->d_inode; error = link_path_walk(s, nd); if (unlikely(error)) - put_link(nd, link, *p); + put_link(nd); return error; } @@ -1869,7 +1873,7 @@ Walked: err = 0; if (unlikely(!s)) { /* jumped */ - put_link(nd, &last->link, last->cookie); + put_link(nd); nd->link_count--; nd->depth--; last--; @@ -1900,7 +1904,7 @@ Walked: terminate_walk(nd); Err: while (unlikely(nd->depth)) { - put_link(nd, &last->link, last->cookie); + put_link(nd); nd->link_count--; nd->depth--; last--; @@ -1910,7 +1914,7 @@ OK: if (unlikely(nd->depth)) { name = last->name; err = walk_component(nd, &next, LOOKUP_FOLLOW); - put_link(nd, &last->link, last->cookie); + put_link(nd); nd->link_count--; nd->depth--; last--; @@ -2065,13 +2069,11 @@ static int path_lookupat(int dfd, const struct filename *name, if (!err && !(flags & LOOKUP_PARENT)) { err = lookup_last(nd, &path); while (err > 0) { - void *cookie; - struct path link = path; - err = follow_link(&link, nd, &cookie); + err = follow_link(nd, &path); if (err) break; err = lookup_last(nd, &path); - put_link(nd, &link, cookie); + put_link(nd); } } @@ -2426,13 +2428,11 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path, err = mountpoint_last(&nd, path); while (err > 0) { - void *cookie; - struct path link = *path; - err = follow_link(&link, &nd, &cookie); + err = follow_link(&nd, path); if (err) break; err = mountpoint_last(&nd, path); - put_link(&nd, &link, cookie); + put_link(&nd); } out: path_cleanup(&nd); @@ -3310,8 +3310,6 @@ static struct file *path_openat(int dfd, struct filename *pathname, error = do_last(nd, &path, file, op, &opened, pathname); while (unlikely(error > 0)) { /* trailing symlink */ - struct path link = path; - void *cookie; if (!(nd->flags & LOOKUP_FOLLOW)) { path_put_conditional(&path, nd); path_put(&nd->path); @@ -3319,11 +3317,11 @@ static struct file *path_openat(int dfd, struct filename *pathname, break; } nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL); - error = follow_link(&link, nd, &cookie); + error = follow_link(nd, &path); if (unlikely(error)) break; error = do_last(nd, &path, file, op, &opened, pathname); - put_link(nd, &link, cookie); + put_link(nd); } out: path_cleanup(nd); -- 2.1.4