Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1123852ybl; Sat, 18 Jan 2020 19:21:44 -0800 (PST) X-Google-Smtp-Source: APXvYqy9xQc0OccAAqx8CMyHuXARza2f5B9/zGbRPiBuSmiFcBYN+g0gS3oT7Tkgauz527+gpegx X-Received: by 2002:a05:6808:143:: with SMTP id h3mr8874625oie.61.1579404104598; Sat, 18 Jan 2020 19:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579404104; cv=none; d=google.com; s=arc-20160816; b=i+xmK565C7a2dzBFDrCMTKRFiLyNPPOQRxt1eZ2lWjAHCpxSxKJwFMv0SwpAoS7/10 gcPs6MJwyG9I4Y0s4rPV9zhNvOoSS5Hfvn9yEXn29z8BW/3O5QPEM8ahm24F5zlRQKfd oqsEJZ/HaOXRZdecJn7Nw72szIdW3UAWsFK52h7no1L95g4ZtdaLqGtzLZCn43bdJIGL I+FI4oUA+nGZS/pkg0Pw+c5zHVNihrhGOxpNe8Eq1oVo0VupJOnDgoMGScId45NG8XrT RUcM6Wb9hlvH5BjSfhL9rW2Od3D4m1tUt1SU36DDNnyS0cgbyo0DgCgvrJeoDPaK6ILX tjSg== 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=/TnGgZX1Hjhh/s7wPlgGbHh9US7b0AguFhEgU6WyFMc=; b=T6UGfcABmtCEC5NeWoYby2hgUPTKwkOAJGhAjavgYVZBC90rjhUQ6KsCLU8qsRD/bP prii+NzRoGVASE2T4NY4VOxcIAY5t9luJEEq3V7J36dB4qlMV8YCUGC7HB9l5jWyBS3U q45zR2fj0vxylzMsY4TWt8a0YRbU7tfGvCOarc/ZZXMXf0eq+aNI5ZDE79jUTVcZyWT2 dOTNxpdxceY0Kf23lSKM4QWGbaUS/ymQalvDRpMnMLyE6eNnC5crJcK5KjJJ6hd3UzW/ 01vNf600QC6k35G/EKuu2fnkSsmSVX8wYB+70I6i1lCkqq/O4YQoT1jrt1H1y3WX/jDX uc4g== 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 y24si15704379oih.24.2020.01.18.19.21.33; Sat, 18 Jan 2020 19:21:44 -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 S1727573AbgASDU1 (ORCPT + 99 others); Sat, 18 Jan 2020 22:20:27 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:56756 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbgASDU0 (ORCPT ); Sat, 18 Jan 2020 22:20:26 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1it17y-00BFY1-D0; Sun, 19 Jan 2020 03:19:58 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Aleksa Sarai , David Howells , Eric Biederman , Christian Brauner , Al Viro Subject: [PATCH 08/17] lookup_open(): saner calling conventions (return dentry on success) Date: Sun, 19 Jan 2020 03:17:20 +0000 Message-Id: <20200119031738.2681033-8-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200119031738.2681033-1-viro@ZenIV.linux.org.uk> References: <20200119031423.GV8904@ZenIV.linux.org.uk> <20200119031738.2681033-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 | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 9d8837432a7b..30503f114142 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3025,10 +3025,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; @@ -3039,7 +3038,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); @@ -3047,7 +3046,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; @@ -3063,7 +3062,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; } /* @@ -3104,14 +3103,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); } - path->mnt = nd->path.mnt; - path->dentry = dentry; - return 0; + return dentry; } no_open: @@ -3147,14 +3142,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); } /* @@ -3171,6 +3163,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; @@ -3227,14 +3220,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) || -- 2.20.1