mac80211: fix ibss race
[safe/jmp/linux-2.6] / net / core / net-sysfs.c
index 146dcfe..427ded8 100644 (file)
@@ -16,7 +16,7 @@
 #include <net/sock.h>
 #include <linux/rtnetlink.h>
 #include <linux/wireless.h>
-#include <net/iw_handler.h>
+#include <net/wext.h>
 
 #include "net-sysfs.h"
 
@@ -77,7 +77,9 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
        if (endp == buf)
                goto err;
 
-       rtnl_lock();
+       if (!rtnl_trylock())
+               return restart_syscall();
+
        if (dev_isalive(net)) {
                if ((ret = (*set)(net, new)) == 0)
                        ret = len;
@@ -139,7 +141,7 @@ static ssize_t show_dormant(struct device *dev,
        return -EINVAL;
 }
 
-static const char *operstates[] = {
+static const char *const operstates[] = {
        "unknown",
        "notpresent", /* currently unused */
        "down",
@@ -223,7 +225,8 @@ static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr,
        if (len >  0 && buf[len - 1] == '\n')
                --count;
 
-       rtnl_lock();
+       if (!rtnl_trylock())
+               return restart_syscall();
        ret = dev_set_alias(netdev, buf, count);
        rtnl_unlock();
 
@@ -236,7 +239,8 @@ static ssize_t show_ifalias(struct device *dev,
        const struct net_device *netdev = to_net_dev(dev);
        ssize_t ret = 0;
 
-       rtnl_lock();
+       if (!rtnl_trylock())
+               return restart_syscall();
        if (netdev->ifalias)
                ret = sprintf(buf, "%s\n", netdev->ifalias);
        rtnl_unlock();
@@ -270,7 +274,6 @@ static ssize_t netstat_show(const struct device *d,
                            unsigned long offset)
 {
        struct net_device *dev = to_net_dev(d);
-       struct net_device_stats *stats;
        ssize_t ret = -EINVAL;
 
        WARN_ON(offset > sizeof(struct net_device_stats) ||
@@ -278,7 +281,7 @@ static ssize_t netstat_show(const struct device *d,
 
        read_lock(&dev_base_lock);
        if (dev_isalive(dev)) {
-               stats = dev->get_stats(dev);
+               const struct net_device_stats *stats = dev_get_stats(dev);
                ret = sprintf(buf, fmt_ulong,
                              *(unsigned long *)(((u8 *) stats) + offset));
        }
@@ -360,18 +363,16 @@ static ssize_t wireless_show(struct device *d, char *buf,
                                               char *))
 {
        struct net_device *dev = to_net_dev(d);
-       const struct iw_statistics *iw = NULL;
+       const struct iw_statistics *iw;
        ssize_t ret = -EINVAL;
 
-       read_lock(&dev_base_lock);
+       rtnl_lock();
        if (dev_isalive(dev)) {
-               if (dev->wireless_handlers &&
-                   dev->wireless_handlers->get_wireless_stats)
-                       iw = dev->wireless_handlers->get_wireless_stats(dev);
-               if (iw != NULL)
+               iw = get_wireless_stats(dev);
+               if (iw)
                        ret = (*format)(iw, buf);
        }
-       read_unlock(&dev_base_lock);
+       rtnl_unlock();
 
        return ret;
 }
@@ -428,6 +429,9 @@ static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
        struct net_device *dev = to_net_dev(d);
        int retval;
 
+       if (!net_eq(dev_net(dev), &init_net))
+               return 0;
+
        /* pass interface to uevent. */
        retval = add_uevent_var(env, "INTERFACE=%s", dev->name);
        if (retval)
@@ -487,20 +491,19 @@ void netdev_unregister_kobject(struct net_device * net)
 int netdev_register_kobject(struct net_device *net)
 {
        struct device *dev = &(net->dev);
-       struct attribute_group **groups = net->sysfs_groups;
+       const struct attribute_group **groups = net->sysfs_groups;
 
        dev->class = &net_class;
        dev->platform_data = net;
        dev->groups = groups;
 
-       BUILD_BUG_ON(BUS_ID_SIZE < IFNAMSIZ);
-       dev_set_name(dev, net->name);
+       dev_set_name(dev, "%s", net->name);
 
 #ifdef CONFIG_SYSFS
        *groups++ = &netstat_group;
 
 #ifdef CONFIG_WIRELESS_EXT_SYSFS
-       if (net->wireless_handlers && net->wireless_handlers->get_wireless_stats)
+       if (net->wireless_handlers || net->ieee80211_ptr)
                *groups++ = &wireless_group;
 #endif
 #endif /* CONFIG_SYSFS */