Re: [PATCH 2.6] sysfs_remove_dir

From: Maneesh Soni
Date: Mon Sep 22 2003 - 23:13:26 EST




Thanks Stephen for letting me know.

Maneesh

Rediffed for 2.6.0-test5.

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/net/core/net-sysfs.c~sysfs-dentry-leak-fix 2003-09-23 09:32:01.000000000 +0530
+++ linux-2.6.0-test5-maneesh/net/core/net-sysfs.c 2003-09-23 09:32:23.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/net/core/dev.c~sysfs-dentry-leak-fix 2003-09-23 09:31:21.000000000 +0530
+++ linux-2.6.0-test5-maneesh/net/core/dev.c 2003-09-23 09:33:04.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 *);


/*******************************************************************************
@@ -2819,7 +2820,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);

_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@xxxxxxxxxx
Phone: 91-80-5044999 Fax: 91-80-5268553
T/L : 9243696
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/