From: Christian Brauner <brauner@kernel.org>
To: NeilBrown <neil@brown.name>
Cc: linux-fsdevel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jan Kara <jack@suse.cz>, Jori Koolstra <jkoolstra@xs4all.nl>,
linux-kernel@vger.kernel.org,
"Christian Brauner (Amutable)" <brauner@kernel.org>
Subject: [PATCH 1/3] fs/namei.c: update stale comments in lookup_open()
Date: Fri, 31 Jul 2026 10:36:05 +0200 [thread overview]
Message-ID: <20260731-work-lookup-fixes-v1-1-2412b85cf65c@kernel.org> (raw)
In-Reply-To: <20260731-work-lookup-fixes-v1-0-2412b85cf65c@kernel.org>
Commit ddb6e6c72a0a ("VFS: move mnt_want_write() and locking into
lookup_open()") moved the parent inode locking into lookup_open(), but
left the comment claiming the caller has to take it. A caller following
that comment now deadlocks, and the series added a second caller.
Describe what the function actually does. While at it drop the claim
that it returns 0 on success and updates @path, wrong ever since
lookup_open() started returning a dentry in v5.7, and fix the reference
to lookup_open() in a comment that now sits inside lookup_open() itself.
Fixes: ddb6e6c72a0a ("VFS: move mnt_want_write() and locking into lookup_open()")
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
fs/namei.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 6db5b7e8547b..226abf613983 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4417,17 +4417,16 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry
/*
* Look up and maybe create and open the last component.
*
- * Must be called with parent locked (exclusive in O_CREAT case).
+ * Takes the parent inode lock itself, exclusive if O_CREAT was requested and
+ * shared otherwise, and drops it again before returning. The caller must not
+ * hold it.
*
- * Returns 0 on success, that is, if
- * the file was successfully atomically created (if necessary) and opened, or
- * the file was not completely opened at this time, though lookups and
- * creations were performed.
- * These case are distinguished by presence of FMODE_OPENED on file->f_mode.
- * In the latter case dentry returned in @path might be negative if O_CREAT
- * hadn't been specified.
+ * On success returns the dentry of the last component. If FMODE_OPENED is set
+ * on file->f_mode the file was also opened and attached to @file; otherwise
+ * only lookup and creation were performed and the caller has to open it. In
+ * the latter case the dentry may be negative if O_CREAT hadn't been specified.
*
- * An error code is returned on failure.
+ * Returns ERR_PTR() on failure.
*/
static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
const struct open_flags *op)
@@ -4452,8 +4451,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
got_write = !mnt_want_write(nd->path.mnt);
/*
* do _not_ fail yet - we might not need that or fail with
- * a different error; let lookup_open() decide; we'll be
- * dropping this one anyway.
+ * a different error; we'll be dropping this one anyway.
*/
}
if (open_flag & O_CREAT)
--
2.53.0
next prev parent reply other threads:[~2026-07-31 8:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 8:36 [PATCH 0/3] fs/namei.c: comment and coding style fixups Christian Brauner
2026-07-31 8:36 ` Christian Brauner [this message]
2026-07-31 8:36 ` [PATCH 2/3] fs/namei.c: fix kerneldoc of atomic_open() and vfs_lookup_open() Christian Brauner
2026-07-31 9:11 ` Jori Koolstra
2026-07-31 10:11 ` Christian Brauner
2026-07-31 8:36 ` [PATCH 3/3] fs/namei.c: fix coding style in atomic_open() and lookup_open() Christian Brauner
2026-07-31 9:20 ` Jori Koolstra
2026-07-31 10:01 ` Christian Brauner
2026-07-31 9:08 ` [PATCH 0/3] fs/namei.c: comment and coding style fixups NeilBrown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260731-work-lookup-fixes-v1-1-2412b85cf65c@kernel.org \
--to=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jkoolstra@xs4all.nl \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®