Skip to content

Commit 4ba9628

Browse files
committed
Merge branch 'work.lookup' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull more ->lookup() cleanups from Al Viro: "Some ->lookup() instances are still overcomplicating the life for themselves, open-coding the stuff that would be handled by d_splice_alias() just fine. Simplify a couple of such cases caught this cycle and document d_splice_alias() intended use" * 'work.lookup' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: Document d_splice_alias() calling conventions for ->lookup() users. simplify btrfs_lookup() clean erofs_lookup()
2 parents 06999fd + 1a16dba commit 4ba9628

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

Documentation/filesystems/porting

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,14 @@ in your dentry operations instead.
622622
alloc_file_clone(file, flags, ops) does not affect any caller's references.
623623
On success you get a new struct file sharing the mount/dentry with the
624624
original, on failure - ERR_PTR().
625+
--
626+
[recommended]
627+
->lookup() instances doing an equivalent of
628+
if (IS_ERR(inode))
629+
return ERR_CAST(inode);
630+
return d_splice_alias(inode, dentry);
631+
don't need to bother with the check - d_splice_alias() will do the
632+
right thing when given ERR_PTR(...) as inode. Moreover, passing NULL
633+
inode to d_splice_alias() will also do the right thing (equivalent of
634+
d_add(dentry, NULL); return NULL;), so that kind of special cases
635+
also doesn't need a separate treatment.

drivers/staging/erofs/namei.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,13 @@ static struct dentry *erofs_lookup(struct inode *dir,
223223
if (err == -ENOENT) {
224224
/* negative dentry */
225225
inode = NULL;
226-
goto negative_out;
227-
} else if (unlikely(err))
228-
return ERR_PTR(err);
229-
230-
debugln("%s, %s (nid %llu) found, d_type %u", __func__,
231-
dentry->d_name.name, nid, d_type);
232-
233-
inode = erofs_iget(dir->i_sb, nid, d_type == EROFS_FT_DIR);
234-
if (IS_ERR(inode))
235-
return ERR_CAST(inode);
236-
237-
negative_out:
226+
} else if (unlikely(err)) {
227+
inode = ERR_PTR(err);
228+
} else {
229+
debugln("%s, %s (nid %llu) found, d_type %u", __func__,
230+
dentry->d_name.name, nid, d_type);
231+
inode = erofs_iget(dir->i_sb, nid, d_type == EROFS_FT_DIR);
232+
}
238233
return d_splice_alias(inode, dentry);
239234
}
240235

fs/btrfs/inode.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5764,16 +5764,10 @@ static int btrfs_dentry_delete(const struct dentry *dentry)
57645764
static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
57655765
unsigned int flags)
57665766
{
5767-
struct inode *inode;
5768-
5769-
inode = btrfs_lookup_dentry(dir, dentry);
5770-
if (IS_ERR(inode)) {
5771-
if (PTR_ERR(inode) == -ENOENT)
5772-
inode = NULL;
5773-
else
5774-
return ERR_CAST(inode);
5775-
}
5767+
struct inode *inode = btrfs_lookup_dentry(dir, dentry);
57765768

5769+
if (inode == ERR_PTR(-ENOENT))
5770+
inode = NULL;
57775771
return d_splice_alias(inode, dentry);
57785772
}
57795773

0 commit comments

Comments
 (0)