All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Emelyanov <xemul@openvz.org>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Linux Netdev List <netdev@vger.kernel.org>,
	Linux Containers <containers@lists.osdl.org>,
	devel@openvz.org, Daniel Lezcano <dlezcano@fr.ibm.com>
Subject: [PATCH][NETNS] Consolidate hashes creation in netdev_init()
Date: Fri, 14 Sep 2007 12:40:49 +0400	[thread overview]
Message-ID: <46EA4911.9070401@openvz.org> (raw)

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>

---

diff --git a/net/core/dev.c b/net/core/dev.c
index a22a95d..1a60ed2 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4258,32 +4258,39 @@ int netdev_compute_features(unsigned lon
 }
 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;
-	}
-
-	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_name_head = netdev_create_hash();
+	if (net->dev_name_head == NULL)
+		goto err_name;
+
+	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)

             reply	other threads:[~2007-09-14  8:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-14  8:40 Pavel Emelyanov [this message]
2007-09-16 22:40 ` [PATCH][NETNS] Consolidate hashes creation in netdev_init() David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46EA4911.9070401@openvz.org \
    --to=xemul@openvz.org \
    --cc=containers@lists.osdl.org \
    --cc=devel@openvz.org \
    --cc=dlezcano@fr.ibm.com \
    --cc=ebiederm@xmission.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.