From 8300807f9e2dffb6552514763ad60e005c12eb94 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 10 Oct 2018 16:37:39 -0400 Subject: [PATCH 1/3] clean erofs_lookup() d_splice_alias() does the right thing when given ERR_PTR(-E...) for inode. No need for gotos, multiple returns, etc. in there. Signed-off-by: Al Viro --- drivers/staging/erofs/namei.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/staging/erofs/namei.c b/drivers/staging/erofs/namei.c index 546a47156101a..8cf0617d4ea01 100644 --- a/drivers/staging/erofs/namei.c +++ b/drivers/staging/erofs/namei.c @@ -223,18 +223,13 @@ static struct dentry *erofs_lookup(struct inode *dir, if (err == -ENOENT) { /* negative dentry */ inode = NULL; - goto negative_out; - } else if (unlikely(err)) - return ERR_PTR(err); - - debugln("%s, %s (nid %llu) found, d_type %u", __func__, - dentry->d_name.name, nid, d_type); - - inode = erofs_iget(dir->i_sb, nid, d_type == EROFS_FT_DIR); - if (IS_ERR(inode)) - return ERR_CAST(inode); - -negative_out: + } else if (unlikely(err)) { + inode = ERR_PTR(err); + } else { + debugln("%s, %s (nid %llu) found, d_type %u", __func__, + dentry->d_name.name, nid, d_type); + inode = erofs_iget(dir->i_sb, nid, d_type == EROFS_FT_DIR); + } return d_splice_alias(inode, dentry); } From 3837d208d8fe7437475c4a1c53fa5e517b16ceb0 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 10 Oct 2018 16:38:27 -0400 Subject: [PATCH 2/3] simplify btrfs_lookup() d_splice_alias() is fine with ERR_PTR(-E...) for inode Signed-off-by: Al Viro --- fs/btrfs/inode.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9357a19d2bff2..fb688c4aa34fc 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5807,16 +5807,10 @@ static int btrfs_dentry_delete(const struct dentry *dentry) static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) { - struct inode *inode; - - inode = btrfs_lookup_dentry(dir, dentry); - if (IS_ERR(inode)) { - if (PTR_ERR(inode) == -ENOENT) - inode = NULL; - else - return ERR_CAST(inode); - } + struct inode *inode = btrfs_lookup_dentry(dir, dentry); + if (inode == ERR_PTR(-ENOENT)) + inode = NULL; return d_splice_alias(inode, dentry); } From 1a16dbaf798c5b68ac767444eb045e6f3adaa16d Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 10 Oct 2018 16:52:37 -0400 Subject: [PATCH 3/3] Document d_splice_alias() calling conventions for ->lookup() users. Short version: it does the right thing when given NULL or ERR_PTR(...) and its calling conventions are chosen to have minimal PITA when used in ->lookup() instances. Signed-off-by: Al Viro --- Documentation/filesystems/porting | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/filesystems/porting b/Documentation/filesystems/porting index 7b7b845c490a4..321d74b739372 100644 --- a/Documentation/filesystems/porting +++ b/Documentation/filesystems/porting @@ -622,3 +622,14 @@ in your dentry operations instead. alloc_file_clone(file, flags, ops) does not affect any caller's references. On success you get a new struct file sharing the mount/dentry with the original, on failure - ERR_PTR(). +-- +[recommended] + ->lookup() instances doing an equivalent of + if (IS_ERR(inode)) + return ERR_CAST(inode); + return d_splice_alias(inode, dentry); + don't need to bother with the check - d_splice_alias() will do the + right thing when given ERR_PTR(...) as inode. Moreover, passing NULL + inode to d_splice_alias() will also do the right thing (equivalent of + d_add(dentry, NULL); return NULL;), so that kind of special cases + also doesn't need a separate treatment.