From patchwork Wed May 13 22:26:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6400751 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9FC969F32B for ; Wed, 13 May 2015 22:28:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C2BB20411 for ; Wed, 13 May 2015 22:28:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 679EF203EB for ; Wed, 13 May 2015 22:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965647AbbEMW0u (ORCPT ); Wed, 13 May 2015 18:26:50 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:44955 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965631AbbEMW0r (ORCPT ); Wed, 13 May 2015 18:26:47 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1Ysf6W-0006mm-NL; Wed, 13 May 2015 22:26:16 +0000 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 14/21] namei: saner calling conventions for filename_parentat() Date: Wed, 13 May 2015 23:26:08 +0100 Message-Id: <1431555975-25997-14-git-send-email-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <20150513222533.GA24192@ZenIV.linux.org.uk> References: <20150513222533.GA24192@ZenIV.linux.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Al Viro a) make it reject ERR_PTR() for name b) make it putname(name) on all other failure exits c) make it return name on success again, simplifies the callers Signed-off-by: Al Viro --- fs/namei.c | 60 ++++++++++++++++++++++-------------------------------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 4588e82..bd45300 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2164,13 +2164,16 @@ static int path_parentat(int dfd, const struct filename *name, return err; } -static int filename_parentat(int dfd, struct filename *name, +static struct filename *filename_parentat(int dfd, struct filename *name, unsigned int flags, struct path *parent, struct qstr *last, int *type) { int retval; - struct nameidata nd, *saved_nd = set_nameidata(&nd); + struct nameidata nd, *saved_nd; + if (IS_ERR(name)) + return name; + saved_nd = set_nameidata(&nd); retval = path_parentat(dfd, name, flags | LOOKUP_RCU, &nd, parent); if (unlikely(retval == -ECHILD)) retval = path_parentat(dfd, name, flags, &nd, parent); @@ -2181,32 +2184,30 @@ static int filename_parentat(int dfd, struct filename *name, *last = nd.last; *type = nd.last_type; audit_inode(name, parent->dentry, LOOKUP_PARENT); + } else { + putname(name); + name = ERR_PTR(retval); } restore_nameidata(saved_nd); - return retval; + return name; } /* does lookup, returns the object with parent locked */ struct dentry *kern_path_locked(const char *name, struct path *path) { - struct filename *filename = getname_kernel(name); + struct filename *filename; + struct dentry *d; struct qstr last; int type; - struct dentry *d; - int err; + filename = filename_parentat(AT_FDCWD, getname_kernel(name), 0, path, + &last, &type); if (IS_ERR(filename)) return ERR_CAST(filename); - - err = filename_parentat(AT_FDCWD, filename, 0, path, &last, &type); - if (err) { - d = ERR_PTR(err); - goto out; - } - if (type != LAST_NORM) { + if (unlikely(type != LAST_NORM)) { path_put(path); - d = ERR_PTR(-EINVAL); - goto out; + putname(filename); + return ERR_PTR(-EINVAL); } mutex_lock_nested(&path->dentry->d_inode->i_mutex, I_MUTEX_PARENT); d = __lookup_hash(&last, path->dentry, 0); @@ -2214,7 +2215,6 @@ struct dentry *kern_path_locked(const char *name, struct path *path) mutex_unlock(&path->dentry->d_inode->i_mutex); path_put(path); } -out: putname(filename); return d; } @@ -2323,21 +2323,9 @@ user_path_parent(int dfd, const char __user *path, int *type, unsigned int flags) { - struct filename *s = getname(path); - int error; - /* only LOOKUP_REVAL is allowed in extra flags */ - flags &= LOOKUP_REVAL; - - if (IS_ERR(s)) - return s; - - error = filename_parentat(dfd, s, flags, parent, last, type); - if (error) { - putname(s); - s = ERR_PTR(error); - } - return s; + return filename_parentat(dfd, getname(path), flags & LOOKUP_REVAL, + parent, last, type); } /** @@ -3401,25 +3389,21 @@ static struct dentry *filename_create(int dfd, struct filename *name, int error; bool is_dir = (lookup_flags & LOOKUP_DIRECTORY); - if (IS_ERR(name)) - return ERR_CAST(name); /* * Note that only LOOKUP_REVAL and LOOKUP_DIRECTORY matter here. Any * other flags passed in are ignored! */ lookup_flags &= LOOKUP_REVAL; - error = filename_parentat(dfd, name, lookup_flags, path, &last, &type); - if (error) { - putname(name); - return ERR_PTR(error); - } + name = filename_parentat(dfd, name, lookup_flags, path, &last, &type); + if (IS_ERR(name)) + return ERR_CAST(name); /* * Yucky last component or no last component at all? * (foo/., foo/.., /////) */ - if (type != LAST_NORM) + if (unlikely(type != LAST_NORM)) goto out; /* don't fail immediately if it's r/o, at least try to report other errors */