• Vegard Nossum's avatar
    dcache: remove unnecessary NULL check in dget_dlock() · 1b6ae9f6
    Vegard Nossum authored
    dget_dlock() requires dentry->d_lock to be held when called, yet
    contains a NULL check for dentry.
    
    An audit of all calls to dget_dlock() shows that it is never called
    with a NULL pointer (as spin_lock()/spin_unlock() would crash in these
    cases):
    
      $ git grep -W '\<dget_dlock\>'
    
      arch/powerpc/platforms/cell/spufs/inode.c-              spin_lock(&dentry->d_lock);
      arch/powerpc/platforms/cell/spufs/inode.c-              if (simple_positive(dentry)) {
      arch/powerpc/platforms/cell/spufs/inode.c:                      dget_dlock(dentry);
    
      fs/autofs/expire.c-             spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED);
      fs/autofs/expire.c-             if (simple_positive(child)) {
      fs/autofs/expire.c:                     dget_dlock(child);
    
      fs/autofs/root.c:                       dget_dlock(active);
      fs/autofs/root.c-                       spin_unlock(&active->d_lock);
    
      fs/autofs/root.c:                       dget_dlock(expiring);
      fs/autofs/root.c-                       spin_unlock(&expiring->d_lock);
    
      fs/ceph/dir.c-          if (!spin_trylock(&dentry->d_lock))
      fs/ceph/dir.c-                  continue;
      [...]
      fs/ceph/dir.c:                          dget_dlock(dentry);
    
      fs/ceph/mds_client.c-           spin_lock(&alias->d_lock);
      [...]
      fs/ceph/mds_client.c:                   dn = dget_dlock(alias);
    
      fs/configfs/inode.c-            spin_lock(&dentry->d_lock);
      fs/configfs/inode.c-            if (simple_positive(dentry)) {
      fs/configfs/inode.c:                    dget_dlock(dentry);
    
      fs/libfs.c:                             found = dget_dlock(d);
      fs/libfs.c-                     spin_unlock(&d->d_lock);
    
      fs/libfs.c:             found = dget_dlock(child);
      fs/libfs.c-     spin_unlock(&child->d_lock);
    
      fs/libfs.c:                             child = dget_dlock(d);
      fs/libfs.c-                     spin_unlock(&d->d_lock);
    
      fs/ocfs2/dcache.c:                      dget_dlock(dentry);
      fs/ocfs2/dcache.c-                      spin_unlock(&dentry->d_lock);
    
      include/linux/dcache.h:static inline struct dentry *dget_dlock(struct dentry *dentry)
    
    After taking out the NULL check, dget_dlock() becomes almost identical
    to __dget_dlock(); the only difference is that dget_dlock() returns the
    dentry that was passed in. These are static inline helpers, so we can
    rely on the compiler to discard unused return values. We can therefore
    also remove __dget_dlock() and replace calls to it by dget_dlock().
    
    Also fix up and improve the kerneldoc comments while we're at it.
    
    Al Viro pointed out that we can also clean up some of the callers to
    make use of the returned value and provided a bit more info for the
    kerneldoc.
    
    While preparing v2 I also noticed that the tabs used in the kerneldoc
    comments were causing the kerneldoc to get parsed incorrectly so I also
    fixed this up (including for d_unhashed, which is otherwise unrelated).
    
    Testing: x86 defconfig build + boot; make htmldocs for the kerneldoc
    warning. objdump shows there are code generation changes.
    
    Link: https://lore.kernel.org/all/20231022164520.915013-1-vegard.nossum@oracle.com/
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: linux-fsdevel@vger.kernel.org
    Cc: Nick Piggin <npiggin@kernel.dk>
    Cc: Waiman Long <Waiman.Long@hp.com>
    Cc: linux-doc@vger.kernel.org
    Signed-off-by: default avatarVegard Nossum <vegard.nossum@oracle.com>
    Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
    1b6ae9f6
dcache.c 83.5 KB