diff options
author | Jiri Pirko <jpirko@redhat.com> | 2010-04-22 20:53:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-04-23 19:37:32 -0400 |
commit | e773aaff8295e7f3428d9cf6f8a476a33de00716 (patch) | |
tree | cdfe16f60d218a7e0ffb4dddd3ff1428703e4190 /net | |
parent | 3b51cc996e81d8a113416d8094fa4a88f8360a51 (diff) |
l2tp: fix memory allocation
Since .size is set properly in "struct pernet_operations l2tp_net_ops",
allocating space for "struct l2tp_net" by hand is not correct, even causes
memory leakage.
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/l2tp/l2tp_core.c | 29 |
1 files changed, 1 insertions, 28 deletions
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index ecc7aea9efe4..1712af1c7b3f 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c | |||
@@ -1617,14 +1617,9 @@ EXPORT_SYMBOL_GPL(l2tp_session_create); | |||
1617 | 1617 | ||
1618 | static __net_init int l2tp_init_net(struct net *net) | 1618 | static __net_init int l2tp_init_net(struct net *net) |
1619 | { | 1619 | { |
1620 | struct l2tp_net *pn; | 1620 | struct l2tp_net *pn = net_generic(net, l2tp_net_id); |
1621 | int err; | ||
1622 | int hash; | 1621 | int hash; |
1623 | 1622 | ||
1624 | pn = kzalloc(sizeof(*pn), GFP_KERNEL); | ||
1625 | if (!pn) | ||
1626 | return -ENOMEM; | ||
1627 | |||
1628 | INIT_LIST_HEAD(&pn->l2tp_tunnel_list); | 1623 | INIT_LIST_HEAD(&pn->l2tp_tunnel_list); |
1629 | spin_lock_init(&pn->l2tp_tunnel_list_lock); | 1624 | spin_lock_init(&pn->l2tp_tunnel_list_lock); |
1630 | 1625 | ||
@@ -1633,33 +1628,11 @@ static __net_init int l2tp_init_net(struct net *net) | |||
1633 | 1628 | ||
1634 | spin_lock_init(&pn->l2tp_session_hlist_lock); | 1629 | spin_lock_init(&pn->l2tp_session_hlist_lock); |
1635 | 1630 | ||
1636 | err = net_assign_generic(net, l2tp_net_id, pn); | ||
1637 | if (err) | ||
1638 | goto out; | ||
1639 | |||
1640 | return 0; | 1631 | return 0; |
1641 | |||
1642 | out: | ||
1643 | kfree(pn); | ||
1644 | return err; | ||
1645 | } | ||
1646 | |||
1647 | static __net_exit void l2tp_exit_net(struct net *net) | ||
1648 | { | ||
1649 | struct l2tp_net *pn; | ||
1650 | |||
1651 | pn = net_generic(net, l2tp_net_id); | ||
1652 | /* | ||
1653 | * if someone has cached our net then | ||
1654 | * further net_generic call will return NULL | ||
1655 | */ | ||
1656 | net_assign_generic(net, l2tp_net_id, NULL); | ||
1657 | kfree(pn); | ||
1658 | } | 1632 | } |
1659 | 1633 | ||
1660 | static struct pernet_operations l2tp_net_ops = { | 1634 | static struct pernet_operations l2tp_net_ops = { |
1661 | .init = l2tp_init_net, | 1635 | .init = l2tp_init_net, |
1662 | .exit = l2tp_exit_net, | ||
1663 | .id = &l2tp_net_id, | 1636 | .id = &l2tp_net_id, |
1664 | .size = sizeof(struct l2tp_net), | 1637 | .size = sizeof(struct l2tp_net), |
1665 | }; | 1638 | }; |