Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=30d97d35851f40fd1c108d1b8904aca3c38d0126
Commit:     30d97d35851f40fd1c108d1b8904aca3c38d0126
Parent:     ad7379d49458a863c520a73a3c36441c572f850e
Author:     Pavel Emelyanov <[EMAIL PROTECTED]>
AuthorDate: Sun Sep 16 15:40:33 2007 -0700
Committer:  David S. Miller <[EMAIL PROTECTED]>
CommitDate: Wed Oct 10 16:51:21 2007 -0700

    [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 <[EMAIL PROTECTED]>
    Signed-off-by: David S. Miller <[EMAIL PROTECTED]>
---
 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 b517d36..cc105ff 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)
 }
 EXPORT_SYMBOL(netdev_compute_features);
 
+static struct hlist_head *netdev_create_hash(void)
+{
+       int i;
+       struct hlist_head *hash;
+
+       hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL);
+       if (hash != NULL)
+               for (i = 0; i < NETDEV_HASHENTRIES; i++)
+                       INIT_HLIST_HEAD(&hash[i]);
+
+       return hash;
+}
+
 /* Initialize per network namespace state */
 static int netdev_init(struct net *net)
 {
-       int i;
        INIT_LIST_HEAD(&net->dev_base_head);
        rwlock_init(&dev_base_lock);
 
-       net->dev_name_head = kmalloc(
-               sizeof(*net->dev_name_head)*NETDEV_HASHENTRIES, GFP_KERNEL);
-       if (!net->dev_name_head)
-               return -ENOMEM;
-
-       net->dev_index_head = kmalloc(
-               sizeof(*net->dev_index_head)*NETDEV_HASHENTRIES, GFP_KERNEL);
-       if (!net->dev_index_head) {
-               kfree(net->dev_name_head);
-               return -ENOMEM;
-       }
+       net->dev_name_head = netdev_create_hash();
+       if (net->dev_name_head == NULL)
+               goto err_name;
 
-       for (i = 0; i < NETDEV_HASHENTRIES; i++)
-               INIT_HLIST_HEAD(&net->dev_name_head[i]);
-
-       for (i = 0; i < NETDEV_HASHENTRIES; i++)
-               INIT_HLIST_HEAD(&net->dev_index_head[i]);
+       net->dev_index_head = netdev_create_hash();
+       if (net->dev_index_head == NULL)
+               goto err_idx;
 
        return 0;
+
+err_idx:
+       kfree(net->dev_name_head);
+err_name:
+       return -ENOMEM;
 }
 
 static void netdev_exit(struct net *net)
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to