Commit 3a737028630bb3c2b9efc38b9ddef2e09b06b808
Committed by
David S. Miller
1 parent
e773aaff82
Exists in
master
and in
39 other branches
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>
Showing 1 changed file with 1 additions and 28 deletions Side-by-side Diff
net/l2tp/l2tp_eth.c
... | ... | @@ -276,43 +276,16 @@ |
276 | 276 | |
277 | 277 | static __net_init int l2tp_eth_init_net(struct net *net) |
278 | 278 | { |
279 | - struct l2tp_eth_net *pn; | |
280 | - int err; | |
279 | + struct l2tp_eth_net *pn = net_generic(net, l2tp_eth_net_id); | |
281 | 280 | |
282 | - pn = kzalloc(sizeof(*pn), GFP_KERNEL); | |
283 | - if (!pn) | |
284 | - return -ENOMEM; | |
285 | - | |
286 | 281 | INIT_LIST_HEAD(&pn->l2tp_eth_dev_list); |
287 | 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 | 284 | return 0; |
294 | - | |
295 | -out: | |
296 | - kfree(pn); | |
297 | - return err; | |
298 | 285 | } |
299 | 286 | |
300 | -static __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 | -} | |
312 | - | |
313 | 287 | static __net_initdata struct pernet_operations l2tp_eth_net_ops = { |
314 | 288 | .init = l2tp_eth_init_net, |
315 | - .exit = l2tp_eth_exit_net, | |
316 | 289 | .id = &l2tp_eth_net_id, |
317 | 290 | .size = sizeof(struct l2tp_eth_net), |
318 | 291 | }; |