[PATCH 4/7] configfs: remove d_add() calls before configfs_attach_group()
From: NeilBrown
Date: Mon Sep 28 2026 - 23:48:58 EST
From: NeilBrown <neil@xxxxxxxxxx>
These d_add() calls cannot be necessary. The inode given is NULL so all
they do is attach the dentry to the hash table.
If configfs_attach_group() fails, then d_drop() is called so the dentry
will be detached.
If configfs_attach_group() succeeds, then
configfs_attach_group -> configfs_attach_item ->configfs_create_dir
must have succeeded, so d_instantiate() will have been called and the
dentry hashed there.
So the only effect is that the dentry will be hashed-negative for a
short period which will allow a lookup to find nothing without waiting
for the directory i_rwsem. I can find no indication that this might be
important.
Adding a dentry as negative, and then later making it positive is an
unusual pattern and appears to be unnecessary, so it is best avoided.
Signed-off-by: NeilBrown <neil@xxxxxxxxxx>
---
fs/configfs/dir.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index 3c88f13f1ca2..145a092171fe 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -715,8 +715,6 @@ static int create_default_group(struct dentry *parent,
ret = -ENOMEM;
child = d_alloc_name(parent, group->cg_item.ci_name);
if (child) {
- d_add(child, NULL);
-
ret = configfs_attach_group(&group->cg_item, child, frag);
if (!ret) {
sd = child->d_fsdata;
@@ -1901,8 +1899,6 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
err = -ENOMEM;
dentry = d_alloc_name(root, group->cg_item.ci_name);
if (dentry) {
- d_add(dentry, NULL);
-
err = configfs_dirent_exists(dentry);
if (!err)
err = configfs_attach_group(&group->cg_item,
--
2.50.0.107.gf914562f5916.dirty