Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp58089ybh; Fri, 13 Mar 2020 17:00:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt2WLK8xFjNIuy2wSQn/IYbCVD8JXNopvgCBXVhPITKACGhuMUltJq42cKoBKzlCYgReum0 X-Received: by 2002:a9d:22:: with SMTP id 31mr12557274ota.173.1584144043904; Fri, 13 Mar 2020 17:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584144043; cv=none; d=google.com; s=arc-20160816; b=QSH1KJ0QLlUFJXYmlKvFmnZRmIDK5mcZi93jVGtnaIzkYC+OHFLL7RlNYy9AtOO4S7 SEgvRc8JGmt3k9zMatvrDmyWgb0WfwHIyjycbwoOQkky434Qi0/uaXTF6kLxB/cQubFb OLxR2CAOPunNylHuVGlZT7EOCLuWriH22p72CbXie3lHEzVo+t0jATevyM1JUXqbmv7g niVlewB6lWAkTuTnDVDt2qOjUKjBmbns5MXM7MavvqVQmWrIfU6FvDhgJfB/9v3zq1cK ytMCqyJF9pyn1XwgyNp+dSWovpqNF5CLWV5iJhN+20uUizSgS5HvS57ZiFpKr0xW4jNV 1yqg== 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=Jbjv54bYy2Wf26z+43MtyTTwkRFz8SXS1W4jOANbuE8=; b=VHRqLrbJfhPTiuwa9ig8iC777mqEhvpADHrxuQZRW9WYszkRqyvXi4X1nQpjR7kwD5 9BkX4/zR5nohRrrH9Uc/XkL7a9lTOVsuBzymZcnCPI6w+VKOYslHdgVu4wfJ4LWfMVK0 T6gk/637HO4QIeT3V5RrKeXyK9x1hK3Qyx/cCeAR2xgIurveUFnYEDiIbZP404b9HXN0 vNHr2SHpJjzdibCFhT+7U65f84xq+EaaVkYG/tOU3CqxZL5spDHpi2nj0w/CJ9B+9aXX PgC+gTz+w64zZu9QRsIjZGYG5xZeNrNUBNhAqtEDZKVfp2N9c4odmTK9yP4ZUmu89Qiy ecXQ== 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 j2si5306255oii.195.2020.03.13.17.00.30; Fri, 13 Mar 2020 17:00:43 -0700 (PDT) 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 S1727742AbgCMX6c (ORCPT + 99 others); Fri, 13 Mar 2020 19:58:32 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:49974 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727680AbgCMXx7 (ORCPT ); Fri, 13 Mar 2020 19:53:59 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCu7q-00B6Yu-2R; Fri, 13 Mar 2020 23:53:58 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v4 08/69] lookup_open(): saner calling conventions (return dentry on success) Date: Fri, 13 Mar 2020 23:52:56 +0000 Message-Id: <20200313235357.2646756-8-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313235357.2646756-1-viro@ZenIV.linux.org.uk> References: <20200313235303.GP23230@ZenIV.linux.org.uk> <20200313235357.2646756-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 | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 5f8b791a6d6e..b350e1e2b46f 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; } /* @@ -3235,19 +3234,9 @@ 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 (file->f_mode & FMODE_OPENED) { - dput(dentry); - return 0; - } - path->mnt = nd->path.mnt; - path->dentry = dentry; - return 0; + if (unlikely(create_error) && dentry == ERR_PTR(-ENOENT)) + dentry = ERR_PTR(create_error); + return dentry; } no_open: @@ -3283,14 +3272,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 +3295,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 +3352,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 +3371,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