From 0123d4ef084c63e65520f2d9ea23f477b2d0c565 Mon Sep 17 00:00:00 2001 From: Maneesh Soni Date: Thu, 25 Sep 2003 07:02:26 -0700 Subject: [PATCH] [NET]: Remove attribute group when unregistering netdev from sysfs. --- net/core/dev.c | 3 ++- net/core/net-sysfs.c | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index d6f77d31f496..8d09c2978972 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -179,6 +179,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); diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 3ff9e58a06c8..b1fa8f6ccc2a 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -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_device *net) #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", -- 2.47.3