]> xenbits.xensource.com Git - people/pauldu/linux.git/commitdiff
fs: simplify misleading code to remove ambiguity regarding ihold()/iput()
authorLuís Henriques <lhenriques@suse.de>
Thu, 28 Sep 2023 15:23:41 +0000 (16:23 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 19 Oct 2023 09:02:48 +0000 (11:02 +0200)
Because 'inode' is being initialised before checking if 'dentry' is negative
it looks like an extra iput() on 'inode' may happen since the ihold() is
done only if the dentry is *not* negative.  In reality this doesn't happen
because d_is_negative() is never true if ->d_inode is NULL.  This patch only
makes the code easier to understand, as I was initially mislead by it.

Signed-off-by: Luís Henriques <lhenriques@suse.de>
Link: https://lore.kernel.org/r/20230928152341.303-1-lhenriques@suse.de
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/namei.c

index 94b27370f468c8cfd4c96aa06be7741f43e75abb..c36ff6f8195adfdb1911f8b12a7b1a59446364c4 100644 (file)
@@ -4367,11 +4367,9 @@ retry_deleg:
        if (!IS_ERR(dentry)) {
 
                /* Why not before? Because we want correct error value */
-               if (last.name[last.len])
+               if (last.name[last.len] || d_is_negative(dentry))
                        goto slashes;
                inode = dentry->d_inode;
-               if (d_is_negative(dentry))
-                       goto slashes;
                ihold(inode);
                error = security_path_unlink(&path, dentry);
                if (error)