linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] fs: simplify misleading code to remove ambiguity regarding ihold()/iput()
@ 2023-09-28 15:23 Luís Henriques
  2023-09-28 16:21 ` Christian Brauner
  0 siblings, 1 reply; 5+ messages in thread
From: Luís Henriques @ 2023-09-28 15:23 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, David Howells
  Cc: Mateusz Guzik, linux-fsdevel, linux-kernel, Luís Henriques

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.

Fixes: b18825a7c8e3 ("VFS: Put a small type field into struct dentry::d_flags")
Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
Changes since v1:
Rephrased commit message to make it clear there isn't a real bug

 fs/namei.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 567ee547492b..156a570d7831 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4386,11 +4386,9 @@ int do_unlinkat(int dfd, struct filename *name)
 	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)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-29  9:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-28 15:23 [PATCH v2] fs: simplify misleading code to remove ambiguity regarding ihold()/iput() Luís Henriques
2023-09-28 16:21 ` Christian Brauner
2023-09-29  9:24   ` Luis Henriques
2023-09-29  9:28     ` Christian Brauner
2023-09-29  9:46       ` Luis Henriques

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).