Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30d97d35 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller
Browse files

[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: default avatarPavel Emelyanov <xemul@openvz.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ad7379d4
Loading
Loading
Loading
Loading
+24 −17
Original line number Diff line number Diff line
@@ -4268,32 +4268,39 @@ int netdev_compute_features(unsigned long all, unsigned long one)
}
EXPORT_SYMBOL(netdev_compute_features);

/* Initialize per network namespace state */
static int netdev_init(struct net *net)
static struct hlist_head *netdev_create_hash(void)
{
	int i;
	INIT_LIST_HEAD(&net->dev_base_head);
	rwlock_init(&dev_base_lock);
	struct hlist_head *hash;

	net->dev_name_head = kmalloc(
		sizeof(*net->dev_name_head)*NETDEV_HASHENTRIES, GFP_KERNEL);
	if (!net->dev_name_head)
		return -ENOMEM;
	hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL);
	if (hash != NULL)
		for (i = 0; i < NETDEV_HASHENTRIES; i++)
			INIT_HLIST_HEAD(&hash[i]);

	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;
	return hash;
}

	for (i = 0; i < NETDEV_HASHENTRIES; i++)
		INIT_HLIST_HEAD(&net->dev_name_head[i]);
/* Initialize per network namespace state */
static int netdev_init(struct net *net)
{
	INIT_LIST_HEAD(&net->dev_base_head);
	rwlock_init(&dev_base_lock);

	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)