Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp870799ybv; Sat, 22 Feb 2020 17:18:29 -0800 (PST) X-Google-Smtp-Source: APXvYqzpsIO6aK5BDdQkt30RFdZP4OF5L/YyEWgqr8eRiliLKP/TxuGsJcjUmbQ94hSlqSEekXkP X-Received: by 2002:a9d:6f0a:: with SMTP id n10mr35952683otq.54.1582420709211; Sat, 22 Feb 2020 17:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582420709; cv=none; d=google.com; s=arc-20160816; b=pOzKwSzF0Mkoae6QNcpAaVEXdCcdUHAatClM0Y90QIbffF8TyRc1NDDXeMNEf3EDFC NWF4NauWAJS33Cq4Ah8Fa6Ohpf8TxudUfoqyfazVRoADLFWGV3FrsfrC1Doxje5dpSKh MClDpdsHYH81hqbRXG6xGqm84yDFDmE46/ZlAljL29nPumH7z5YlM3q9gp3x48IigOL9 SI/MB+imWlFsr2NAlcYck0JiqnlmisaVNTW8AroJCUO8Jt2WSo+ZheBiVSjC10wl+rf1 zrEWwQnyihcxKqqZ7VbDIEhmGz+HZsGSzq7d5F4Ri0bhZqiKMSI94ejxztKm41Hdl2jV 0wVQ== 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=aW4KYZoaYVEZLxDRyjpe15emYfn9J96sdQ1RdVeN0BM=; b=OQmbtsmx9GrwMRfVcGVwb8D7jmHIyoNiTpAHvzxYsu8Mss/FPecO6E84DkxXZwSUxW uodGBQVKTHpBOoX3PKqucMnpvFVFreHbXTp1Afm7WQ6n3Jk9r16IlAYxpCWrN3VuxAcb CA4d/AQF8AUaCiC3z6S9a7Bm9ndbm8Tk8X0WNAlILkzyREvOhXyf1IejMKsBmoV1MRwB /ta75FM+ofGQ+Dpy0tWZTfYOX+ok66JP1VOjVR8qAn17dkB+ITVT7SebyCR9KChd2SYY b5/s4NXiAuUjcmnMmiTYvc+TBgk6OG6j2+02JDiF8qfKMEhIiaX2CpNrm3YYHz4B71gY BBUQ== 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 w20si3057466oic.103.2020.02.22.17.18.17; Sat, 22 Feb 2020 17:18:29 -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 S1727158AbgBWBSJ (ORCPT + 99 others); Sat, 22 Feb 2020 20:18:09 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:50110 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726934AbgBWBSJ (ORCPT ); Sat, 22 Feb 2020 20:18:09 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j5fu5-00HDbq-IW; Sun, 23 Feb 2020 01:17:56 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v2 07/34] atomic_open(): saner calling conventions (return dentry on success) Date: Sun, 23 Feb 2020 01:15:59 +0000 Message-Id: <20200223011626.4103706-7-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 Currently it either returns -E... or puts (nd->path.mnt,dentry) into *path and returns 0. Make it return ERR_PTR(-E...) or dentry; adjust the caller. Fewer arguments and it's easier to keep track of *path contents that way. Signed-off-by: Al Viro --- fs/namei.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c104ec75faef..5f8b791a6d6e 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3087,10 +3087,10 @@ static int may_o_create(const struct path *dir, struct dentry *dentry, umode_t m * * Returns an error code otherwise. */ -static int atomic_open(struct nameidata *nd, struct dentry *dentry, - struct path *path, struct file *file, - const struct open_flags *op, - int open_flag, umode_t mode) +static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, + struct file *file, + const struct open_flags *op, + int open_flag, umode_t mode) { struct dentry *const DENTRY_NOT_SET = (void *) -1UL; struct inode *dir = nd->path.dentry->d_inode; @@ -3131,17 +3131,15 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, } if (file->f_mode & FMODE_CREATED) fsnotify_create(dir, dentry); - if (unlikely(d_is_negative(dentry))) { + if (unlikely(d_is_negative(dentry))) error = -ENOENT; - } else { - path->dentry = dentry; - path->mnt = nd->path.mnt; - return 0; - } } } - dput(dentry); - return error; + if (error) { + dput(dentry); + dentry = ERR_PTR(error); + } + return dentry; } /* @@ -3236,11 +3234,20 @@ static int lookup_open(struct nameidata *nd, struct path *path, } if (dir_inode->i_op->atomic_open) { - error = atomic_open(nd, dentry, path, file, op, open_flag, - mode); - if (unlikely(error == -ENOENT) && create_error) - error = create_error; - return error; + 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; } no_open: -- 2.11.0