diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2007-09-16 18:40:33 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:51:21 -0400 |
commit | 30d97d35851f40fd1c108d1b8904aca3c38d0126 (patch) | |
tree | af45c94eceaa1e30c7df51852bfb4e6e33e67721 | |
parent | ad7379d49458a863c520a73a3c36441c572f850e (diff) |
[NETNS]: Consolidate hashes creation in netdev_init()
The dev_name_hash and the dev_index_hash are now booth kmalloc-ed
(and each element is properly initialized as usually) so I think
it's worth consolidating this code making it look nicer (and
saving 28 bytes of .text section ;) )
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/core/dev.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index b517d36e653e..cc105ff67db5 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -4268,32 +4268,39 @@ int netdev_compute_features(unsigned long all, unsigned long one) | |||
4268 | } | 4268 | } |
4269 | EXPORT_SYMBOL(netdev_compute_features); | 4269 | EXPORT_SYMBOL(netdev_compute_features); |
4270 | 4270 | ||
4271 | static struct hlist_head *netdev_create_hash(void) | ||
4272 | { | ||
4273 | int i; | ||
4274 | struct hlist_head *hash; | ||
4275 | |||
4276 | hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL); | ||
4277 | if (hash != NULL) | ||
4278 | for (i = 0; i < NETDEV_HASHENTRIES; i++) | ||
4279 | INIT_HLIST_HEAD(&hash[i]); | ||
4280 | |||
4281 | return hash; | ||
4282 | } | ||
4283 | |||
4271 | /* Initialize per network namespace state */ | 4284 | /* Initialize per network namespace state */ |
4272 | static int netdev_init(struct net *net) | 4285 | static int netdev_init(struct net *net) |
4273 | { | 4286 | { |
4274 | int i; | ||
4275 | INIT_LIST_HEAD(&net->dev_base_head); | 4287 | INIT_LIST_HEAD(&net->dev_base_head); |
4276 | rwlock_init(&dev_base_lock); | 4288 | rwlock_init(&dev_base_lock); |
4277 | 4289 | ||
4278 | net->dev_name_head = kmalloc( | 4290 | net->dev_name_head = netdev_create_hash(); |
4279 | sizeof(*net->dev_name_head)*NETDEV_HASHENTRIES, GFP_KERNEL); | 4291 | if (net->dev_name_head == NULL) |
4280 | if (!net->dev_name_head) | 4292 | goto err_name; |
4281 | return -ENOMEM; | ||
4282 | |||
4283 | net->dev_index_head = kmalloc( | ||
4284 | sizeof(*net->dev_index_head)*NETDEV_HASHENTRIES, GFP_KERNEL); | ||
4285 | if (!net->dev_index_head) { | ||
4286 | kfree(net->dev_name_head); | ||
4287 | return -ENOMEM; | ||
4288 | } | ||
4289 | 4293 | ||
4290 | for (i = 0; i < NETDEV_HASHENTRIES; i++) | 4294 | net->dev_index_head = netdev_create_hash(); |
4291 | INIT_HLIST_HEAD(&net->dev_name_head[i]); | 4295 | if (net->dev_index_head == NULL) |
4292 | 4296 | goto err_idx; | |
4293 | for (i = 0; i < NETDEV_HASHENTRIES; i++) | ||
4294 | INIT_HLIST_HEAD(&net->dev_index_head[i]); | ||
4295 | 4297 | ||
4296 | return 0; | 4298 | return 0; |
4299 | |||
4300 | err_idx: | ||
4301 | kfree(net->dev_name_head); | ||
4302 | err_name: | ||
4303 | return -ENOMEM; | ||
4297 | } | 4304 | } |
4298 | 4305 | ||
4299 | static void netdev_exit(struct net *net) | 4306 | static void netdev_exit(struct net *net) |