]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dcache.c: more idiomatic "positives are not allowed" sanity checks
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 24 Jan 2026 06:32:07 +0000 (01:32 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 2 Apr 2026 08:09:37 +0000 (04:09 -0400)
Several functions have BUG_ON/WARN_ON sanity checks that want to verify
that dentry is not positive and instead of looking at ->d_inode (as we
do in all other places that check that) they look at ->d_alias.
Just use the normal helpers instead - that way we no longer even look
at ->d_alias for negative dentries

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/dcache.c

index 4378eb8a00bbad03432ba15f39991055474193bc..616a445ec7207afd1d66880f602a8992137eb9a7 100644 (file)
@@ -428,7 +428,7 @@ static inline void __d_clear_type_and_inode(struct dentry *dentry)
 
 static void dentry_free(struct dentry *dentry)
 {
-       WARN_ON(!hlist_unhashed(&dentry->d_alias));
+       WARN_ON(d_really_is_positive(dentry));
        if (unlikely(dname_external(dentry))) {
                struct external_name *p = external_name(dentry);
                if (likely(atomic_dec_and_test(&p->count))) {
@@ -2004,7 +2004,7 @@ static void __d_instantiate(struct dentry *dentry, struct inode *inode)
  
 void d_instantiate(struct dentry *entry, struct inode * inode)
 {
-       BUG_ON(!hlist_unhashed(&entry->d_alias));
+       BUG_ON(d_really_is_positive(entry));
        if (inode) {
                security_d_instantiate(entry, inode);
                spin_lock(&inode->i_lock);
@@ -2024,7 +2024,7 @@ EXPORT_SYMBOL(d_instantiate);
  */
 void d_instantiate_new(struct dentry *entry, struct inode *inode)
 {
-       BUG_ON(!hlist_unhashed(&entry->d_alias));
+       BUG_ON(d_really_is_positive(entry));
        BUG_ON(!inode);
        lockdep_annotate_inode_mutex_key(inode);
        security_d_instantiate(entry, inode);
@@ -2795,7 +2795,7 @@ EXPORT_SYMBOL(d_add);
 
 struct dentry *d_make_persistent(struct dentry *dentry, struct inode *inode)
 {
-       WARN_ON(!hlist_unhashed(&dentry->d_alias));
+       WARN_ON(d_really_is_positive(dentry));
        WARN_ON(!inode);
        security_d_instantiate(dentry, inode);
        spin_lock(&inode->i_lock);
@@ -3185,7 +3185,7 @@ void d_mark_tmpfile(struct file *file, struct inode *inode)
        struct dentry *dentry = file->f_path.dentry;
 
        BUG_ON(dname_external(dentry) ||
-               !hlist_unhashed(&dentry->d_alias) ||
+               d_really_is_positive(dentry) ||
                !d_unlinked(dentry));
        spin_lock(&dentry->d_parent->d_lock);
        spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);