Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965661AbbEMW0v (ORCPT ); Wed, 13 May 2015 18:26:51 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:44951 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965603AbbEMW0o (ORCPT ); Wed, 13 May 2015 18:26:44 -0400 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 13/21] namei: saner calling conventions for filename_create() Date: Wed, 13 May 2015 23:26:07 +0100 Message-Id: <1431555975-25997-13-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-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2600 Lines: 92 From: Al Viro a) make it reject ERR_PTR() for name b) make it putname(name) upon return in all other cases. seriously simplifies the callers... Signed-off-by: Al Viro --- fs/namei.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index dbd1a34..4588e82 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3401,6 +3401,8 @@ 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! @@ -3408,8 +3410,10 @@ static struct dentry *filename_create(int dfd, struct filename *name, lookup_flags &= LOOKUP_REVAL; error = filename_parentat(dfd, name, lookup_flags, path, &last, &type); - if (error) + if (error) { + putname(name); return ERR_PTR(error); + } /* * Yucky last component or no last component at all? @@ -3447,6 +3451,7 @@ static struct dentry *filename_create(int dfd, struct filename *name, error = err2; goto fail; } + putname(name); return dentry; fail: dput(dentry); @@ -3457,20 +3462,15 @@ unlock: mnt_drop_write(path->mnt); out: path_put(path); + putname(name); return dentry; } struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path, unsigned int lookup_flags) { - struct filename *filename = getname_kernel(pathname); - struct dentry *res; - - if (IS_ERR(filename)) - return ERR_CAST(filename); - res = filename_create(dfd, filename, path, lookup_flags); - putname(filename); - return res; + return filename_create(dfd, getname_kernel(pathname), + path, lookup_flags); } EXPORT_SYMBOL(kern_path_create); @@ -3486,13 +3486,7 @@ EXPORT_SYMBOL(done_path_create); struct dentry *user_path_create(int dfd, const char __user *pathname, struct path *path, unsigned int lookup_flags) { - struct filename *tmp = getname(pathname); - struct dentry *res; - if (IS_ERR(tmp)) - return ERR_CAST(tmp); - res = filename_create(dfd, tmp, path, lookup_flags); - putname(tmp); - return res; + return filename_create(dfd, getname(pathname), path, lookup_flags); } EXPORT_SYMBOL(user_path_create); -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/