public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Maneesh Soni <maneesh@in.ibm.com>
To: Patrick Mochel <mochel@osdl.org>
Cc: Andrew Morton <akpm@osdl.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Dipankar Sarma <dipankar@in.ibm.com>,
	Hanna Linder <hannal@us.ibm.com>
Subject: Re: [PATCH 2.6] sysfs_remove_dir
Date: Mon, 22 Sep 2003 10:28:35 +0530	[thread overview]
Message-ID: <20030922045835.GA18755@in.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0309191556281.950-100000@localhost.localdomain>

On Fri, Sep 19, 2003 at 04:02:15PM -0700, Patrick Mochel wrote:
> 
> > sysfs_remove_dir() does not remove the contents of subdirs corresponding
> > to the attribute groups of a kobject. The following patch fixes this by first
> > removing the subdir contents and then removing thus emptied subdirs along
> > with the other attribute files of the kobject and plugs the memory
> > leakage resulting from orphan dentries.
> > 
> > I tested it by inserting and removing "dummy.o" network module and verifying
> > that dentires corresponding to "statistics" attribute group are removed.
> 
> Sorry it's taken a while to reply, but I even now haven't had a chance to 
> look that deep into this problem. I will say that this is the wrong 
> approach to the problem. 
> 
> Upon initial inspection, it looks like it will do the right thing in all 
> cases, except when a parent is removed before a child is (but we don't 
> technically support that now). 
> 
> However, I'd like to move away from the automatic cleanup that sysfs was 
> doing. attribute groups make it easier to clean up all the files that are 
> created for an object when the object is removed. I would like to see that 
> removal call inserted where necessary, instead of adding this complication 
> to the sysfs core.
> 
> I intend to remove the automatic cleanup in sysfs_remove_dir(), but 
> haven't gotten around to it.. 
> 

ok.. my intention was not to change callers for removing attribute group and 
keep the changes within sysfs. But if you prefer otherway (I too :-)), please 
see the patch below. As of now I can see only netdev not releasing attribute 
group. I guess power subsystem don't need to remove attribute groups created 
in pm_init() and pm_disk_init() as these don't unregister from sysfs.

Thanks
Maneesh

o attribute group should be removed while unregistering from sysfs. netdev
  does not do this and leaks dentries belonging to the attribute group. 
  The following patch removes the attribute group when netdev is unregistered.


 net/core/dev.c       |    3 ++-
 net/core/net-sysfs.c |   25 +++++++++++++++++++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff -puN net/core/net-sysfs.c~sysfs-dentry-leak-fix net/core/net-sysfs.c
--- linux-2.6.0-test5-mm3/net/core/net-sysfs.c~sysfs-dentry-leak-fix	2003-09-22 09:45:04.000000000 +0530
+++ linux-2.6.0-test5-mm3-maneesh/net/core/net-sysfs.c	2003-09-22 09:45:17.000000000 +0530
@@ -383,6 +383,21 @@ static struct class net_class = {
 #endif
 };
 
+void netdev_unregister_sysfs(struct net_device * net)
+{
+	struct class_device * class_dev = &(net->class_dev);
+
+	if (net->get_stats)
+		sysfs_remove_group(&class_dev->kobj, &netstat_group);
+
+#ifdef WIRELESS_EXT
+	if (net->get_wireless_stats)
+		sysfs_remove_group(&class_dev->kobj, &wireless_group);
+#endif
+	class_device_del(class_dev);
+
+}
+
 /* Create sysfs entries for network device. */
 int netdev_register_sysfs(struct net_device *net)
 {
@@ -411,9 +426,15 @@ int netdev_register_sysfs(struct net_dev
 #ifdef WIRELESS_EXT
 	if (net->get_wireless_stats &&
 	    (ret = sysfs_create_group(&class_dev->kobj, &wireless_group)))
-		goto out_unreg; 
-#endif
+		goto out_cleanup; 
+
+	return 0;
+out_cleanup:
+	if (net->get_stats)
+		sysfs_remove_group(&class_dev->kobj, &netstat_group);
+#else
 	return 0;
+#endif
 
 out_unreg:
 	printk(KERN_WARNING "%s: sysfs attribute registration failed %d\n",
diff -puN net/core/dev.c~sysfs-dentry-leak-fix net/core/dev.c
--- linux-2.6.0-test5-mm3/net/core/dev.c~sysfs-dentry-leak-fix	2003-09-22 09:45:08.000000000 +0530
+++ linux-2.6.0-test5-mm3-maneesh/net/core/dev.c	2003-09-22 09:45:17.000000000 +0530
@@ -183,6 +183,7 @@ int netdev_fastroute_obstacles;
 
 extern int netdev_sysfs_init(void);
 extern int netdev_register_sysfs(struct net_device *);
+extern int netdev_unregister_sysfs(struct net_device *);
 #ifdef CONFIG_KGDB
 extern int kgdb_net_interrupt(struct sk_buff *skb);
 #endif
@@ -2834,7 +2835,7 @@ void netdev_run_todo(void)
 			break;
 
 		case NETREG_UNREGISTERING:
-			class_device_del(&dev->class_dev);
+			netdev_unregister_sysfs(dev);
 			dev->reg_state = NETREG_UNREGISTERED;
 
 			netdev_wait_allrefs(dev);

_


  reply	other threads:[~2003-09-22  4:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-15 10:21 [PATCH 2.6] sysfs_remove_dir Maneesh Soni
2003-09-15 21:36 ` Hanna Linder
2003-09-19 23:02 ` Patrick Mochel
2003-09-22  4:58   ` Maneesh Soni [this message]
2003-09-23  4:09     ` Maneesh Soni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030922045835.GA18755@in.ibm.com \
    --to=maneesh@in.ibm.com \
    --cc=akpm@osdl.org \
    --cc=dipankar@in.ibm.com \
    --cc=hannal@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mochel@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox