Skip to content

Commit 6036c5f

Browse files
Luís Henriquesbrauner
authored andcommitted
fs: simplify misleading code to remove ambiguity regarding ihold()/iput()
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>
1 parent 85fadf8 commit 6036c5f

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

fs/namei.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,11 +4367,9 @@ int do_unlinkat(int dfd, struct filename *name)
43674367
if (!IS_ERR(dentry)) {
43684368

43694369
/* Why not before? Because we want correct error value */
4370-
if (last.name[last.len])
4370+
if (last.name[last.len] || d_is_negative(dentry))
43714371
goto slashes;
43724372
inode = dentry->d_inode;
4373-
if (d_is_negative(dentry))
4374-
goto slashes;
43754373
ihold(inode);
43764374
error = security_path_unlink(&path, dentry);
43774375
if (error)

0 commit comments

Comments
 (0)