aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Pirko <jpirko@redhat.com>2010-04-22 21:01:52 -0400
committerDavid S. Miller <davem@davemloft.net>2010-04-23 19:37:33 -0400
commit3a737028630bb3c2b9efc38b9ddef2e09b06b808 (patch)
treed1d1a4fbaa71f966f4f9b793a792211d59fda834
parente773aaff8295e7f3428d9cf6f8a476a33de00716 (diff)
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: Jiri Pirko <jpirko@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/l2tp/l2tp_eth.c29
1 files changed, 1 insertions, 28 deletions
diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
index ca1164afeb74..58c6c4cda73b 100644
--- a/net/l2tp/l2tp_eth.c
+++ b/net/l2tp/l2tp_eth.c
@@ -276,43 +276,16 @@ out:
276 276
277static __net_init int l2tp_eth_init_net(struct net *net) 277static __net_init int l2tp_eth_init_net(struct net *net)
278{ 278{
279 struct l2tp_eth_net *pn; 279 struct l2tp_eth_net *pn = net_generic(net, l2tp_eth_net_id);
280 int err;
281
282 pn = kzalloc(sizeof(*pn), GFP_KERNEL);
283 if (!pn)
284 return -ENOMEM;
285 280
286 INIT_LIST_HEAD(&pn->l2tp_eth_dev_list); 281 INIT_LIST_HEAD(&pn->l2tp_eth_dev_list);
287 spin_lock_init(&pn->l2tp_eth_lock); 282 spin_lock_init(&pn->l2tp_eth_lock);
288 283
289 err = net_assign_generic(net, l2tp_eth_net_id, pn);
290 if (err)
291 goto out;
292
293 return 0; 284 return 0;
294
295out:
296 kfree(pn);
297 return err;
298}
299
300static __net_exit void l2tp_eth_exit_net(struct net *net)
301{
302 struct l2tp_eth_net *pn;
303
304 pn = net_generic(net, l2tp_eth_net_id);
305 /*
306 * if someone has cached our net then
307 * further net_generic call will return NULL
308 */
309 net_assign_generic(net, l2tp_eth_net_id, NULL);
310 kfree(pn);
311} 285}
312 286
313static __net_initdata struct pernet_operations l2tp_eth_net_ops = { 287static __net_initdata struct pernet_operations l2tp_eth_net_ops = {
314 .init = l2tp_eth_init_net, 288 .init = l2tp_eth_init_net,
315 .exit = l2tp_eth_exit_net,
316 .id = &l2tp_eth_net_id, 289 .id = &l2tp_eth_net_id,
317 .size = sizeof(struct l2tp_eth_net), 290 .size = sizeof(struct l2tp_eth_net),
318}; 291};