Skip to contentSkip to conversation

Fix dentry refcounting in sysfs_remove_group()

PATCH New Maneesh Soni 1 participant 1 message Feb 17, 2004 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix dentry refcounting in sysfs_remove_group()

Hello,

Please review the following patch fixing the dentry refcounting during sysfs_remove_group().

Thanks
Maneesh

o The following patch fixes the dentry refcounting, during sysfs_remove_group() and also adds the missing dput() for the "extra" ref taken during sysfs_create() for the sub-directory dentry corresponding to attribute group.

 fs/sysfs/dir.c   |    2 ++
 fs/sysfs/group.c |    5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)
fs/sysfs/dir.c renamed from fs/sysfs/dir.c~sysfs_remove_subdir-dentry-leak-fix +2 -0
diff -puN fs/sysfs/dir.c~sysfs_remove_subdir-dentry-leak-fix fs/sysfs/dir.c
@@ -96,6 +96,8 @@ static void remove_dir(struct dentry * d
 void sysfs_remove_subdir(struct dentry * d)
 {
 	remove_dir(d);
+	/* release the "extra" ref taken during sysfs_create() */
+	dput(d);
 }
 
 
fs/sysfs/group.c renamed from fs/sysfs/group.c~sysfs_remove_subdir-dentry-leak-fix +3 -2
diff -puN fs/sysfs/group.c~sysfs_remove_subdir-dentry-leak-fix fs/sysfs/group.c
@@ -68,12 +68,13 @@ void sysfs_remove_group(struct kobject *
 	if (grp->name)
 		dir = sysfs_get_dentry(kobj->dentry,grp->name);
 	else
-		dir = kobj->dentry;
+		dir = dget(kobj->dentry);
 
 	remove_files(dir,grp);
-	dput(dir);
 	if (grp->name)
 		sysfs_remove_subdir(dir);
+	/* release the ref. taken in this routine */
+	dput(dir);
 }
 
 

_

Signature · 6 lines
Maneesh Soni
Linux Technology Center, 
IBM Software Lab, Bangalore, India
email: [email protected]
Phone: 91-80-25044999 Fax: 91-80-5268553
T/L : 9243696