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

Commit 3a737028 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller
Browse files

l2tp_eth: fix memory allocation



Since .size is set properly in "struct pernet_operations l2tp_eth_net_ops",
allocating space for "struct l2tp_eth_net" by hand is not correct, even causes
memory leakage.

Signed-off-by: default avatarJiri Pirko <jpirko@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e773aaff
Loading
Loading
Loading
Loading
+1 −28
Original line number Original line Diff line number Diff line
@@ -276,43 +276,16 @@ static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 p


static __net_init int l2tp_eth_init_net(struct net *net)
static __net_init int l2tp_eth_init_net(struct net *net)
{
{
	struct l2tp_eth_net *pn;
	struct l2tp_eth_net *pn = net_generic(net, l2tp_eth_net_id);
	int err;

	pn = kzalloc(sizeof(*pn), GFP_KERNEL);
	if (!pn)
		return -ENOMEM;


	INIT_LIST_HEAD(&pn->l2tp_eth_dev_list);
	INIT_LIST_HEAD(&pn->l2tp_eth_dev_list);
	spin_lock_init(&pn->l2tp_eth_lock);
	spin_lock_init(&pn->l2tp_eth_lock);


	err = net_assign_generic(net, l2tp_eth_net_id, pn);
	if (err)
		goto out;

	return 0;
	return 0;

out:
	kfree(pn);
	return err;
}

static __net_exit void l2tp_eth_exit_net(struct net *net)
{
	struct l2tp_eth_net *pn;

	pn = net_generic(net, l2tp_eth_net_id);
	/*
	 * if someone has cached our net then
	 * further net_generic call will return NULL
	 */
	net_assign_generic(net, l2tp_eth_net_id, NULL);
	kfree(pn);
}
}


static __net_initdata struct pernet_operations l2tp_eth_net_ops = {
static __net_initdata struct pernet_operations l2tp_eth_net_ops = {
	.init = l2tp_eth_init_net,
	.init = l2tp_eth_init_net,
	.exit = l2tp_eth_exit_net,
	.id   = &l2tp_eth_net_id,
	.id   = &l2tp_eth_net_id,
	.size = sizeof(struct l2tp_eth_net),
	.size = sizeof(struct l2tp_eth_net),
};
};