Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp871098ybv; Sat, 22 Feb 2020 17:18:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzRQB1KC6RJwCPfg+NT3Hz6/Ca2vpL332BYn+JwM/TE+bFD0K1ZPwrNT/CVFXbmQY/gFjPP X-Received: by 2002:a05:6830:1555:: with SMTP id l21mr32912158otp.41.1582420734099; Sat, 22 Feb 2020 17:18:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582420734; cv=none; d=google.com; s=arc-20160816; b=Y+gewMJbFLI+F0/whDMeuZlW9Suh/PXE/SEz2t0ZYTfM3SAdHKiKwShhw798kpgZ2J XTr7Eoh1EKFjCg0ko7NUScx3oa7ZfwpgtQ2JQzrXeIinV78AKmC5I+pSivg3O+mYLVsC 0hlgD6+q5Pp9ljxIVZYVvLUC9ZSZy3VQgsCueGsRyC17mFD1zpOXNYHvhtDxFvFg5vf5 0XIfgNlXCSEywfYYbkZu5QGDqil9/f1CsNit3wWA6oeGZ23lYnDLpbwgmBeVJnhNLn2p DUq+ya36QtysynfN0APDFD4paHIev20Wm4Fx65JdHFBeu64NOngb5Rq8oIxeJwobdI1j QErg== 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=AbmXWNsx/bU/MqluOtMDlbmo9PikXJj5qTGdsJm81n8=; b=0M5KmYVU0Cuhvej2LxU3KnHU7413dLxMu+c2Y8ffP7kyjF4Bri1h40GnmiAGKF2bC+ AqGAAbAQdVFjBCZuvZnoKxNAUGWO312cTQdCb9tr9jN9lRDCAUU4OPzCc1AQcNjYDQvn fanKnfeKTgfgjS4ei2VWtjaT80k4G6BxjXZVvj2CG88B0jbslgNUyPmxCD9tZRi76Q8z +a8eaO+DACXoT7fV9vF6iY7z3SqcvmkQcDZOMOOM6xFjHzpGce6RImfopmUDz1YqV27c kXaJ3siMFYLhXgXfyNGRY4JoM2rc5y1Za6TDIK15iGchE6yZxWPhzwHbDb3PShywocS5 z0/w== 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 s129si3253669oig.177.2020.02.22.17.18.42; Sat, 22 Feb 2020 17:18:54 -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 S1727249AbgBWBSh (ORCPT + 99 others); Sat, 22 Feb 2020 20:18:37 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:50118 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726934AbgBWBSh (ORCPT ); Sat, 22 Feb 2020 20:18:37 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j5fuK-00HDcF-9m; Sun, 23 Feb 2020 01:18:13 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v2 08/34] lookup_open(): saner calling conventions (return dentry on success) Date: Sun, 23 Feb 2020 01:16:00 +0000 Message-Id: <20200223011626.4103706-8-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200223011626.4103706-1-viro@ZenIV.linux.org.uk> References: <20200223011154.GY23230@ZenIV.linux.org.uk> <20200223011626.4103706-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 same story as for atomic_open() in the previous commit. Signed-off-by: Al Viro --- fs/namei.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 5f8b791a6d6e..4946d006ba20 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3157,10 +3157,9 @@ static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, * * An error code is returned on failure. */ -static int lookup_open(struct nameidata *nd, struct path *path, - struct file *file, - const struct open_flags *op, - bool got_write) +static struct dentry *lookup_open(struct nameidata *nd, struct file *file, + const struct open_flags *op, + bool got_write) { struct dentry *dir = nd->path.dentry; struct inode *dir_inode = dir->d_inode; @@ -3171,7 +3170,7 @@ static int lookup_open(struct nameidata *nd, struct path *path, DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq); if (unlikely(IS_DEADDIR(dir_inode))) - return -ENOENT; + return ERR_PTR(-ENOENT); file->f_mode &= ~FMODE_CREATED; dentry = d_lookup(dir, &nd->last); @@ -3179,7 +3178,7 @@ static int lookup_open(struct nameidata *nd, struct path *path, if (!dentry) { dentry = d_alloc_parallel(dir, &nd->last, &wq); if (IS_ERR(dentry)) - return PTR_ERR(dentry); + return dentry; } if (d_in_lookup(dentry)) break; @@ -3195,7 +3194,7 @@ static int lookup_open(struct nameidata *nd, struct path *path, } if (dentry->d_inode) { /* Cached positive dentry: will open in f_op->open */ - goto out_no_open; + return dentry; } /* @@ -3236,18 +3235,10 @@ static int lookup_open(struct nameidata *nd, struct path *path, if (dir_inode->i_op->atomic_open) { dentry = atomic_open(nd, dentry, file, op, open_flag, mode); if (IS_ERR(dentry)) { - error = PTR_ERR(dentry); - if (unlikely(error == -ENOENT) && create_error) - error = create_error; - return error; + if (dentry == ERR_PTR(-ENOENT) && create_error) + dentry = ERR_PTR(create_error); } - if (file->f_mode & FMODE_OPENED) { - dput(dentry); - return 0; - } - path->mnt = nd->path.mnt; - path->dentry = dentry; - return 0; + return dentry; } no_open: @@ -3283,14 +3274,11 @@ static int lookup_open(struct nameidata *nd, struct path *path, error = create_error; goto out_dput; } -out_no_open: - path->dentry = dentry; - path->mnt = nd->path.mnt; - return 0; + return dentry; out_dput: dput(dentry); - return error; + return ERR_PTR(error); } /* @@ -3309,6 +3297,7 @@ static int do_last(struct nameidata *nd, unsigned seq; struct inode *inode; struct path path; + struct dentry *dentry; int error; nd->flags &= ~LOOKUP_PARENT; @@ -3365,14 +3354,18 @@ static int do_last(struct nameidata *nd, inode_lock(dir->d_inode); else inode_lock_shared(dir->d_inode); - error = lookup_open(nd, &path, file, op, got_write); + dentry = lookup_open(nd, file, op, got_write); if (open_flag & O_CREAT) inode_unlock(dir->d_inode); else inode_unlock_shared(dir->d_inode); - if (error) + if (IS_ERR(dentry)) { + error = PTR_ERR(dentry); goto out; + } + path.mnt = nd->path.mnt; + path.dentry = dentry; if (file->f_mode & FMODE_OPENED) { if ((file->f_mode & FMODE_CREATED) || @@ -3380,6 +3373,7 @@ static int do_last(struct nameidata *nd, will_truncate = false; audit_inode(nd->name, file->f_path.dentry, 0); + dput(dentry); goto opened; } -- 2.11.0