]> Pileus Git - ~andy/linux/blobdiff - net/core/net-sysfs.c
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux...
[~andy/linux] / net / core / net-sysfs.c
index 79159db6acb9ba54d2280d30fb0b79cdf8cfec9f..7635d3f7272324f06866754ffd22df48408fc455 100644 (file)
@@ -18,6 +18,9 @@
 #include <linux/wireless.h>
 #include <net/iw_handler.h>
 
+#include "net-sysfs.h"
+
+#ifdef CONFIG_SYSFS
 static const char fmt_hex[] = "%#x\n";
 static const char fmt_long_hex[] = "%#lx\n";
 static const char fmt_dec[] = "%d\n";
@@ -92,17 +95,6 @@ NETDEVICE_SHOW(type, fmt_dec);
 NETDEVICE_SHOW(link_mode, fmt_dec);
 
 /* use same locking rules as GIFHWADDR ioctl's */
-static ssize_t format_addr(char *buf, const unsigned char *addr, int len)
-{
-       int i;
-       char *cp = buf;
-
-       for (i = 0; i < len; i++)
-               cp += sprintf(cp, "%02x%c", addr[i],
-                             i == (len - 1) ? '\n' : ':');
-       return cp - buf;
-}
-
 static ssize_t show_address(struct device *dev, struct device_attribute *attr,
                            char *buf)
 {
@@ -111,7 +103,7 @@ static ssize_t show_address(struct device *dev, struct device_attribute *attr,
 
        read_lock(&dev_base_lock);
        if (dev_isalive(net))
-           ret = format_addr(buf, net->dev_addr, net->addr_len);
+               ret = sysfs_format_mac(buf, net->dev_addr, net->addr_len);
        read_unlock(&dev_base_lock);
        return ret;
 }
@@ -121,7 +113,7 @@ static ssize_t show_broadcast(struct device *dev,
 {
        struct net_device *net = to_net_dev(dev);
        if (dev_isalive(net))
-               return format_addr(buf, net->broadcast, net->addr_len);
+               return sysfs_format_mac(buf, net->broadcast, net->addr_len);
        return -EINVAL;
 }
 
@@ -244,9 +236,8 @@ static ssize_t netstat_show(const struct device *d,
        struct net_device_stats *stats;
        ssize_t ret = -EINVAL;
 
-       if (offset > sizeof(struct net_device_stats) ||
-           offset % sizeof(unsigned long) != 0)
-               WARN_ON(1);
+       WARN_ON(offset > sizeof(struct net_device_stats) ||
+                       offset % sizeof(unsigned long) != 0);
 
        read_lock(&dev_base_lock);
        if (dev_isalive(dev) && dev->get_stats &&
@@ -392,29 +383,25 @@ static struct attribute_group wireless_group = {
 };
 #endif
 
+#endif /* CONFIG_SYSFS */
+
 #ifdef CONFIG_HOTPLUG
-static int netdev_uevent(struct device *d, char **envp,
-                        int num_envp, char *buf, int size)
+static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
 {
        struct net_device *dev = to_net_dev(d);
-       int retval, len = 0, i = 0;
+       int retval;
 
        /* pass interface to uevent. */
-       retval = add_uevent_var(envp, num_envp, &i,
-                               buf, size, &len,
-                               "INTERFACE=%s", dev->name);
+       retval = add_uevent_var(env, "INTERFACE=%s", dev->name);
        if (retval)
                goto exit;
 
        /* pass ifindex to uevent.
         * ifindex is useful as it won't change (interface name may change)
         * and is what RtNetlink uses natively. */
-       retval = add_uevent_var(envp, num_envp, &i,
-                               buf, size, &len,
-                               "IFINDEX=%d", dev->ifindex);
+       retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex);
 
 exit:
-       envp[i] = NULL;
        return retval;
 }
 #endif
@@ -435,7 +422,9 @@ static void netdev_release(struct device *d)
 static struct class net_class = {
        .name = "net",
        .dev_release = netdev_release,
+#ifdef CONFIG_SYSFS
        .dev_attrs = net_class_attributes,
+#endif /* CONFIG_SYSFS */
 #ifdef CONFIG_HOTPLUG
        .dev_uevent = netdev_uevent,
 #endif
@@ -444,7 +433,7 @@ static struct class net_class = {
 /* Delete sysfs entries but hold kobject reference until after all
  * netdev references are gone.
  */
-void netdev_unregister_sysfs(struct net_device * net)
+void netdev_unregister_kobject(struct net_device * net)
 {
        struct device *dev = &(net->dev);
 
@@ -453,7 +442,7 @@ void netdev_unregister_sysfs(struct net_device * net)
 }
 
 /* Create sysfs entries for network device. */
-int netdev_register_sysfs(struct net_device *net)
+int netdev_register_kobject(struct net_device *net)
 {
        struct device *dev = &(net->dev);
        struct attribute_group **groups = net->sysfs_groups;
@@ -466,6 +455,7 @@ int netdev_register_sysfs(struct net_device *net)
        BUILD_BUG_ON(BUS_ID_SIZE < IFNAMSIZ);
        strlcpy(dev->bus_id, net->name, BUS_ID_SIZE);
 
+#ifdef CONFIG_SYSFS
        if (net->get_stats)
                *groups++ = &netstat_group;
 
@@ -473,11 +463,12 @@ int netdev_register_sysfs(struct net_device *net)
        if (net->wireless_handlers && net->wireless_handlers->get_wireless_stats)
                *groups++ = &wireless_group;
 #endif
+#endif /* CONFIG_SYSFS */
 
        return device_add(dev);
 }
 
-int netdev_sysfs_init(void)
+int netdev_kobject_init(void)
 {
        return class_register(&net_class);
 }