Commit fe9925b5 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

[NET]: Create netdev attribute_groups with class_device_add

Atomically create attributes when class device is added. This avoids
the race between registering class_device (which generates hotplug
event), and the creation of attribute groups.
Signed-off-by: default avatarStephen Hemminger <shemminger@osdl.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1498221d
...@@ -506,6 +506,8 @@ struct net_device ...@@ -506,6 +506,8 @@ struct net_device
/* class/net/name entry */ /* class/net/name entry */
struct class_device class_dev; struct class_device class_dev;
/* space for optional statistics and wireless sysfs groups */
struct attribute_group *sysfs_groups[3];
}; };
#define NETDEV_ALIGN 32 #define NETDEV_ALIGN 32
......
...@@ -3043,11 +3043,11 @@ void netdev_run_todo(void) ...@@ -3043,11 +3043,11 @@ void netdev_run_todo(void)
switch(dev->reg_state) { switch(dev->reg_state) {
case NETREG_REGISTERING: case NETREG_REGISTERING:
dev->reg_state = NETREG_REGISTERED;
err = netdev_register_sysfs(dev); err = netdev_register_sysfs(dev);
if (err) if (err)
printk(KERN_ERR "%s: failed sysfs registration (%d)\n", printk(KERN_ERR "%s: failed sysfs registration (%d)\n",
dev->name, err); dev->name, err);
dev->reg_state = NETREG_REGISTERED;
break; break;
case NETREG_UNREGISTERING: case NETREG_UNREGISTERING:
......
...@@ -29,7 +29,7 @@ static const char fmt_ulong[] = "%lu\n"; ...@@ -29,7 +29,7 @@ static const char fmt_ulong[] = "%lu\n";
static inline int dev_isalive(const struct net_device *dev) static inline int dev_isalive(const struct net_device *dev)
{ {
return dev->reg_state == NETREG_REGISTERED; return dev->reg_state <= NETREG_REGISTERED;
} }
/* use same locking rules as GIF* ioctl's */ /* use same locking rules as GIF* ioctl's */
...@@ -445,58 +445,33 @@ static struct class net_class = { ...@@ -445,58 +445,33 @@ static struct class net_class = {
void netdev_unregister_sysfs(struct net_device * net) void netdev_unregister_sysfs(struct net_device * net)
{ {
struct class_device * class_dev = &(net->class_dev); class_device_del(&(net->class_dev));
if (net->get_stats)
sysfs_remove_group(&class_dev->kobj, &netstat_group);
#ifdef WIRELESS_EXT
if (net->get_wireless_stats || (net->wireless_handlers &&
net->wireless_handlers->get_wireless_stats))
sysfs_remove_group(&class_dev->kobj, &wireless_group);
#endif
class_device_del(class_dev);
} }
/* Create sysfs entries for network device. */ /* Create sysfs entries for network device. */
int netdev_register_sysfs(struct net_device *net) int netdev_register_sysfs(struct net_device *net)
{ {
struct class_device *class_dev = &(net->class_dev); struct class_device *class_dev = &(net->class_dev);
int ret; struct attribute_group **groups = net->sysfs_groups;
class_device_initialize(class_dev);
class_dev->class = &net_class; class_dev->class = &net_class;
class_dev->class_data = net; class_dev->class_data = net;
class_dev->groups = groups;
BUILD_BUG_ON(BUS_ID_SIZE < IFNAMSIZ);
strlcpy(class_dev->class_id, net->name, BUS_ID_SIZE); strlcpy(class_dev->class_id, net->name, BUS_ID_SIZE);
if ((ret = class_device_register(class_dev)))
goto out;
if (net->get_stats && if (net->get_stats)
(ret = sysfs_create_group(&class_dev->kobj, &netstat_group))) *groups++ = &netstat_group;
goto out_unreg;
#ifdef WIRELESS_EXT #ifdef WIRELESS_EXT
if (net->get_wireless_stats || (net->wireless_handlers && if (net->get_wireless_stats
net->wireless_handlers->get_wireless_stats)) { || (net->wireless_handlers && net->wireless_handlers->get_wireless_stats))
ret = sysfs_create_group(&class_dev->kobj, &wireless_group); *groups++ = &wireless_group;
if (ret)
goto out_cleanup;
}
return 0;
out_cleanup:
if (net->get_stats)
sysfs_remove_group(&class_dev->kobj, &netstat_group);
#else
return 0;
#endif #endif
out_unreg: return class_device_add(class_dev);
printk(KERN_WARNING "%s: sysfs attribute registration failed %d\n",
net->name, ret);
class_device_unregister(class_dev);
out:
return ret;
} }
int netdev_sysfs_init(void) int netdev_sysfs_init(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment