[PATCH 1/3] vfs: move create error && negative dentry case in lookup_open() up
Jori Koolstra <[email protected]> Fri, 10 Jul 2026 18:42:31 +0200
| Newsgroups | org.kernel.vger.audit,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
O_CREAT is stripped when create_error is set in lookup_open(), so when lookup does not return an inode, the case if (!dentry->d_inode && (open_flag & O_CREAT)) is always skipped. We can get rid of this cognitive step by handling the error case first. Reviewed-by: NeilBrown <[email protected]> Signed-off-by: Jori Koolstra <[email protected]> --- fs/namei.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 19ce43c9a6e6..447eda7cbe34 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4491,6 +4491,11 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, } } + if (unlikely(create_error) && !dentry->d_inode) { + error = create_error; + goto out_dput; + } + /* Negative dentry, just create the file */ if (!dentry->d_inode && (open_flag & O_CREAT)) { /* but break the directory lease first! */ @@ -4510,10 +4515,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, if (error) goto out_dput; } - if (unlikely(create_error) && !dentry->d_inode) { - error = create_error; - goto out_dput; - } + return dentry; out_dput: -- 2.55.0