Subject: [PATCH] nethost: loopback cleanups From: Eric W. Biederman Date: 1134819647 -0700 - Use semicolons not commas at the end of statements. - Add loopback_uninit to cleanup the state of the loopback statistics - Have each nethost call regsiter_netdev/unregister_netdev on behalf of the loopback device. --- drivers/net/loopback.c | 45 ++++++++++++++++++++++----------------------- include/linux/nethost.h | 1 - net/core/host.c | 8 +++++--- 3 files changed, 27 insertions(+), 27 deletions(-) 5514e90ce9c1540aaaf832d1ce1d131d37779d7c diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c index 2e28791..193e009 100644 --- a/drivers/net/loopback.c +++ b/drivers/net/loopback.c @@ -200,30 +200,38 @@ static struct ethtool_ops loopback_ethto .set_tso = ethtool_op_set_tso, }; +static void loopback_uninit(struct net_device *dev) +{ + struct net_device_stats *stats = dev->priv; + dev->priv = NULL; + kfree(stats); +} + /* Setup and register the loopback device. */ int loopback_init(struct net_device *dev) { struct net_device_stats *stats; strcpy(dev->name, (dev == &init_host.loopback_dev)?"lo": "lo%d"); - dev->mtu = (16 * 1024) + 20 + 20 + 12, - dev->hard_start_xmit = loopback_xmit, - dev->hard_header = eth_header, - dev->hard_header_cache = eth_header_cache, - dev->header_cache_update = eth_header_cache_update, - dev->hard_header_len = ETH_HLEN, /* 14 */ - dev->addr_len = ETH_ALEN, /* 6 */ - dev->tx_queue_len = 0, - dev->type = ARPHRD_LOOPBACK, /* 0x0001*/ - dev->rebuild_header = eth_rebuild_header, - dev->flags = IFF_LOOPBACK, + dev->mtu = (16 * 1024) + 20 + 20 + 12; + dev->uninit = loopback_uninit; + dev->hard_start_xmit = loopback_xmit; + dev->hard_header = eth_header; + dev->hard_header_cache = eth_header_cache; + dev->header_cache_update = eth_header_cache_update; + dev->hard_header_len = ETH_HLEN; /* 14 */ + dev->addr_len = ETH_ALEN; /* 6 */ + dev->tx_queue_len = 0; + dev->type = ARPHRD_LOOPBACK; /* 0x0001*/ + dev->rebuild_header = eth_rebuild_header; + dev->flags = IFF_LOOPBACK; dev->features = NETIF_F_SG | NETIF_F_FRAGLIST #ifdef LOOPBACK_TSO | NETIF_F_TSO #endif | NETIF_F_NO_CSUM | NETIF_F_HIGHDMA - | NETIF_F_LLTX, - dev->ethtool_ops = &loopback_ethtool_ops, + | NETIF_F_LLTX; + dev->ethtool_ops = &loopback_ethtool_ops; /* Can survive without statistics */ stats = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL); @@ -232,14 +240,5 @@ int loopback_init(struct net_device *dev dev->priv = stats; dev->get_stats = &get_stats; } - - return register_netdev(dev); + return 0; }; - -void loopback_free(struct net_device *dev) -{ - struct net_device_stats *stats = dev->priv; - unregister_netdev(dev); - if (stats) - kfree(stats); -} diff --git a/include/linux/nethost.h b/include/linux/nethost.h index 48c4e15..1105826 100644 --- a/include/linux/nethost.h +++ b/include/linux/nethost.h @@ -19,7 +19,6 @@ struct nethost { extern struct nethost init_host; extern int loopback_init(struct net_device *loopback_dev); -extern void loopback_free(struct net_device *loopback_dev); #ifdef CONFIG_NET diff --git a/net/core/host.c b/net/core/host.c index 9c8c62d..72e3ceb 100644 --- a/net/core/host.c +++ b/net/core/host.c @@ -8,7 +8,7 @@ static void do_put_host(void *arg) { struct nethost *host = arg; - loopback_free(&host->loopback_dev); + unregister_netdev(&host->loopback_dev); kfree(host); } @@ -35,7 +35,8 @@ int __copy_host(int flags, struct task_s up_read(&uts_sem); dev = &host->loopback_dev; - err = loopback_init(dev); + dev->init = loopback_init; + err = register_netdev(dev); if (err) goto out_free_host; @@ -56,5 +57,6 @@ out_free_host: __init int nethost_init(void) { - return loopback_init(&init_host.loopback_dev); + init_host.loopback_dev.init = loopback_init; + return register_netdev(&init_host.loopback_dev); } -- 1.0.GIT