Subject: [PATCH] sysfs_remove_subdir-dentry-leak-fix.patch
From: Maneesh Soni <[email-masked]>
To: Andrew Morton <[email-masked]>
Cc: Greg KH <[email-masked]>
Date: Wed, 10 Mar 2004 13:05:51 +0530

Hello Andrew,

The current sysfs_remove_subdir-dentry-leak-fix.patch in -mm tree is buggy. It
seems to still leak dentry in case of un-named attribute group 
(grp->name == NULL). I request you to please replace it with the following 
patch.

Thanks
Maneesh

o The following patch fixes the dentry refcounting, during sysfs_create_group()
  sysfs_remove_group() 

 fs/sysfs/group.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff -puN fs/sysfs/group.c~sysfs_remove_subdir-dentry-leak-fix fs/sysfs/group.c
--- linux-2.6.4-rc2-mm1/fs/sysfs/group.c~sysfs_remove_subdir-dentry-leak-fix	2004-03-10 11:54:07.000000000 +0530
+++ linux-2.6.4-rc2-mm1-maneesh/fs/sysfs/group.c	2004-03-10 11:54:33.000000000 +0530
@@ -55,8 +55,8 @@ int sysfs_create_group(struct kobject * 
 	if ((error = create_files(dir,grp))) {
 		if (grp->name)
 			sysfs_remove_subdir(dir);
-		dput(dir);
 	}
+	dput(dir);
 	return error;
 }
 
@@ -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);
 }

_
-- 
Maneesh Soni
Linux Technology Center, 
IBM Software Lab, Bangalore, India
email: [email-masked]
Phone: 91-80-25044999 Fax: 91-80-25268553
T/L : 9243696