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

[NET]: Dynamic allocation for dummy net device.

parent 068990ad
...@@ -51,15 +51,9 @@ static int dummy_accept_fastpath(struct net_device *dev, struct dst_entry *dst) ...@@ -51,15 +51,9 @@ static int dummy_accept_fastpath(struct net_device *dev, struct dst_entry *dst)
} }
#endif #endif
static int __init dummy_init(struct net_device *dev) static void __init dummy_setup(struct net_device *dev)
{ {
/* Initialize the device structure. */ /* Initialize the device structure. */
dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
if (dev->priv == NULL)
return -ENOMEM;
memset(dev->priv, 0, sizeof(struct net_device_stats));
dev->get_stats = dummy_get_stats; dev->get_stats = dummy_get_stats;
dev->hard_start_xmit = dummy_xmit; dev->hard_start_xmit = dummy_xmit;
dev->set_multicast_list = set_multicast_list; dev->set_multicast_list = set_multicast_list;
...@@ -72,8 +66,7 @@ static int __init dummy_init(struct net_device *dev) ...@@ -72,8 +66,7 @@ static int __init dummy_init(struct net_device *dev)
dev->tx_queue_len = 0; dev->tx_queue_len = 0;
dev->flags |= IFF_NOARP; dev->flags |= IFF_NOARP;
dev->flags &= ~IFF_MULTICAST; dev->flags &= ~IFF_MULTICAST;
SET_MODULE_OWNER(dev);
return 0;
} }
static int dummy_xmit(struct sk_buff *skb, struct net_device *dev) static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)
...@@ -92,32 +85,30 @@ static struct net_device_stats *dummy_get_stats(struct net_device *dev) ...@@ -92,32 +85,30 @@ static struct net_device_stats *dummy_get_stats(struct net_device *dev)
return dev->priv; return dev->priv;
} }
static struct net_device dev_dummy; static struct net_device *dev_dummy;
static int __init dummy_init_module(void) static int __init dummy_init_module(void)
{ {
int err; int err;
dev_dummy.init = dummy_init; dev_dummy = alloc_netdev(sizeof(struct net_device_stats),
SET_MODULE_OWNER(&dev_dummy); "dummy%d", dummy_setup);
/* Find a name for this unit */ if (!dev_dummy)
err=dev_alloc_name(&dev_dummy,"dummy%d"); return -ENOMEM;
if(err<0)
return err; if ((err = register_netdev(dev_dummy))) {
err = register_netdev(&dev_dummy); kfree(dev_dummy);
if (err<0) dev_dummy = NULL;
}
return err; return err;
return 0;
} }
static void __exit dummy_cleanup_module(void) static void __exit dummy_cleanup_module(void)
{ {
unregister_netdev(&dev_dummy); unregister_netdev(dev_dummy);
kfree(dev_dummy.priv); kfree(dev_dummy);
dev_dummy = NULL;
memset(&dev_dummy, 0, sizeof(dev_dummy));
dev_dummy.init = dummy_init;
} }
module_init(dummy_init_module); module_init(dummy_init_module);
......
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