Commit 8b41d188 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller

[NET]: Fix running without sysfs

When sysfs support is compiled out the kernel still keeps and maintains
the kobject tree.  So it is not safe to skip our kobject reference counting or
to avoid becoming members of the kobject tree.  It is safe to not add
the networking specific sysfs attributes.

This patch removes the sysfs special cases from net/core/dev.c
renames functions from netdev_sysfs_xxxx to netdev_kobject_xxxx
and always compiles in net-sysfs.c

net-sysfs.c is modified with a CONFIG_SYSFS guard around the parts
that are actually sysfs specific.
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bb293e6a
...@@ -11,7 +11,7 @@ obj-y += dev.o ethtool.o dev_mcast.o dst.o netevent.o \ ...@@ -11,7 +11,7 @@ obj-y += dev.o ethtool.o dev_mcast.o dst.o netevent.o \
neighbour.o rtnetlink.o utils.o link_watch.o filter.o neighbour.o rtnetlink.o utils.o link_watch.o filter.o
obj-$(CONFIG_XFRM) += flow.o obj-$(CONFIG_XFRM) += flow.o
obj-$(CONFIG_SYSFS) += net-sysfs.o obj-y += net-sysfs.o
obj-$(CONFIG_NET_PKTGEN) += pktgen.o obj-$(CONFIG_NET_PKTGEN) += pktgen.o
obj-$(CONFIG_NETPOLL) += netpoll.o obj-$(CONFIG_NETPOLL) += netpoll.o
obj-$(CONFIG_NET_DMA) += user_dma.o obj-$(CONFIG_NET_DMA) += user_dma.o
......
...@@ -249,15 +249,9 @@ static RAW_NOTIFIER_HEAD(netdev_chain); ...@@ -249,15 +249,9 @@ static RAW_NOTIFIER_HEAD(netdev_chain);
DEFINE_PER_CPU(struct softnet_data, softnet_data); DEFINE_PER_CPU(struct softnet_data, softnet_data);
#ifdef CONFIG_SYSFS extern int netdev_kobject_init(void);
extern int netdev_sysfs_init(void); extern int netdev_register_kobject(struct net_device *);
extern int netdev_register_sysfs(struct net_device *); extern void netdev_unregister_kobject(struct net_device *);
extern void netdev_unregister_sysfs(struct net_device *);
#else
#define netdev_sysfs_init() (0)
#define netdev_register_sysfs(dev) (0)
#define netdev_unregister_sysfs(dev) do { } while(0)
#endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC #ifdef CONFIG_DEBUG_LOCK_ALLOC
/* /*
...@@ -3575,7 +3569,7 @@ int register_netdevice(struct net_device *dev) ...@@ -3575,7 +3569,7 @@ int register_netdevice(struct net_device *dev)
if (!dev->rebuild_header) if (!dev->rebuild_header)
dev->rebuild_header = default_rebuild_header; dev->rebuild_header = default_rebuild_header;
ret = netdev_register_sysfs(dev); ret = netdev_register_kobject(dev);
if (ret) if (ret)
goto err_uninit; goto err_uninit;
dev->reg_state = NETREG_REGISTERED; dev->reg_state = NETREG_REGISTERED;
...@@ -3838,7 +3832,6 @@ EXPORT_SYMBOL(alloc_netdev_mq); ...@@ -3838,7 +3832,6 @@ EXPORT_SYMBOL(alloc_netdev_mq);
*/ */
void free_netdev(struct net_device *dev) void free_netdev(struct net_device *dev)
{ {
#ifdef CONFIG_SYSFS
/* Compatibility with error handling in drivers */ /* Compatibility with error handling in drivers */
if (dev->reg_state == NETREG_UNINITIALIZED) { if (dev->reg_state == NETREG_UNINITIALIZED) {
kfree((char *)dev - dev->padded); kfree((char *)dev - dev->padded);
...@@ -3850,9 +3843,6 @@ void free_netdev(struct net_device *dev) ...@@ -3850,9 +3843,6 @@ void free_netdev(struct net_device *dev)
/* will free via device release */ /* will free via device release */
put_device(&dev->dev); put_device(&dev->dev);
#else
kfree((char *)dev - dev->padded);
#endif
} }
/* Synchronize with packet receive processing. */ /* Synchronize with packet receive processing. */
...@@ -3921,8 +3911,8 @@ void unregister_netdevice(struct net_device *dev) ...@@ -3921,8 +3911,8 @@ void unregister_netdevice(struct net_device *dev)
/* Notifier chain MUST detach us from master device. */ /* Notifier chain MUST detach us from master device. */
BUG_TRAP(!dev->master); BUG_TRAP(!dev->master);
/* Remove entries from sysfs */ /* Remove entries from kobject tree */
netdev_unregister_sysfs(dev); netdev_unregister_kobject(dev);
/* Finish processing unregister after unlock */ /* Finish processing unregister after unlock */
net_set_todo(dev); net_set_todo(dev);
...@@ -4053,9 +4043,9 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char ...@@ -4053,9 +4043,9 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
dev->iflink = dev->ifindex; dev->iflink = dev->ifindex;
} }
/* Fixup sysfs */ /* Fixup kobjects */
err = device_rename(&dev->dev, dev->name); err = device_rename(&dev->dev, dev->name);
BUG_ON(err); WARN_ON(err);
/* Add the device back in the hashes */ /* Add the device back in the hashes */
list_netdevice(dev); list_netdevice(dev);
...@@ -4358,7 +4348,7 @@ static int __init net_dev_init(void) ...@@ -4358,7 +4348,7 @@ static int __init net_dev_init(void)
if (dev_proc_init()) if (dev_proc_init())
goto out; goto out;
if (netdev_sysfs_init()) if (netdev_kobject_init())
goto out; goto out;
INIT_LIST_HEAD(&ptype_all); INIT_LIST_HEAD(&ptype_all);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/wireless.h> #include <linux/wireless.h>
#include <net/iw_handler.h> #include <net/iw_handler.h>
#ifdef CONFIG_SYSFS
static const char fmt_hex[] = "%#x\n"; static const char fmt_hex[] = "%#x\n";
static const char fmt_long_hex[] = "%#lx\n"; static const char fmt_long_hex[] = "%#lx\n";
static const char fmt_dec[] = "%d\n"; static const char fmt_dec[] = "%d\n";
...@@ -392,6 +393,8 @@ static struct attribute_group wireless_group = { ...@@ -392,6 +393,8 @@ static struct attribute_group wireless_group = {
}; };
#endif #endif
#endif /* CONFIG_SYSFS */
#ifdef CONFIG_HOTPLUG #ifdef CONFIG_HOTPLUG
static int netdev_uevent(struct device *d, char **envp, static int netdev_uevent(struct device *d, char **envp,
int num_envp, char *buf, int size) int num_envp, char *buf, int size)
...@@ -435,7 +438,9 @@ static void netdev_release(struct device *d) ...@@ -435,7 +438,9 @@ static void netdev_release(struct device *d)
static struct class net_class = { static struct class net_class = {
.name = "net", .name = "net",
.dev_release = netdev_release, .dev_release = netdev_release,
#ifdef CONFIG_SYSFS
.dev_attrs = net_class_attributes, .dev_attrs = net_class_attributes,
#endif /* CONFIG_SYSFS */
#ifdef CONFIG_HOTPLUG #ifdef CONFIG_HOTPLUG
.dev_uevent = netdev_uevent, .dev_uevent = netdev_uevent,
#endif #endif
...@@ -444,7 +449,7 @@ static struct class net_class = { ...@@ -444,7 +449,7 @@ static struct class net_class = {
/* Delete sysfs entries but hold kobject reference until after all /* Delete sysfs entries but hold kobject reference until after all
* netdev references are gone. * 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); struct device *dev = &(net->dev);
...@@ -453,7 +458,7 @@ void netdev_unregister_sysfs(struct net_device * net) ...@@ -453,7 +458,7 @@ void netdev_unregister_sysfs(struct net_device * net)
} }
/* Create sysfs entries for network device. */ /* 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 device *dev = &(net->dev);
struct attribute_group **groups = net->sysfs_groups; struct attribute_group **groups = net->sysfs_groups;
...@@ -466,6 +471,7 @@ int netdev_register_sysfs(struct net_device *net) ...@@ -466,6 +471,7 @@ int netdev_register_sysfs(struct net_device *net)
BUILD_BUG_ON(BUS_ID_SIZE < IFNAMSIZ); BUILD_BUG_ON(BUS_ID_SIZE < IFNAMSIZ);
strlcpy(dev->bus_id, net->name, BUS_ID_SIZE); strlcpy(dev->bus_id, net->name, BUS_ID_SIZE);
#ifdef CONFIG_SYSFS
if (net->get_stats) if (net->get_stats)
*groups++ = &netstat_group; *groups++ = &netstat_group;
...@@ -473,11 +479,12 @@ int netdev_register_sysfs(struct net_device *net) ...@@ -473,11 +479,12 @@ int netdev_register_sysfs(struct net_device *net)
if (net->wireless_handlers && net->wireless_handlers->get_wireless_stats) if (net->wireless_handlers && net->wireless_handlers->get_wireless_stats)
*groups++ = &wireless_group; *groups++ = &wireless_group;
#endif #endif
#endif /* CONFIG_SYSFS */
return device_add(dev); return device_add(dev);
} }
int netdev_sysfs_init(void) int netdev_kobject_init(void)
{ {
return class_register(&net_class); return class_register(&net_class);
} }
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