Skip to content

Commit 3a73702

Browse files
Jiri Pirkodavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e773aaf commit 3a73702

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed

net/l2tp/l2tp_eth.c

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -276,43 +276,16 @@ static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 p
276276

277277
static __net_init int l2tp_eth_init_net(struct net *net)
278278
{
279-
struct l2tp_eth_net *pn;
280-
int err;
281-
282-
pn = kzalloc(sizeof(*pn), GFP_KERNEL);
283-
if (!pn)
284-
return -ENOMEM;
279+
struct l2tp_eth_net *pn = net_generic(net, l2tp_eth_net_id);
285280

286281
INIT_LIST_HEAD(&pn->l2tp_eth_dev_list);
287282
spin_lock_init(&pn->l2tp_eth_lock);
288283

289-
err = net_assign_generic(net, l2tp_eth_net_id, pn);
290-
if (err)
291-
goto out;
292-
293284
return 0;
294-
295-
out:
296-
kfree(pn);
297-
return err;
298-
}
299-
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);
311285
}
312286

313287
static __net_initdata struct pernet_operations l2tp_eth_net_ops = {
314288
.init = l2tp_eth_init_net,
315-
.exit = l2tp_eth_exit_net,
316289
.id = &l2tp_eth_net_id,
317290
.size = sizeof(struct l2tp_eth_net),
318291
};

0 commit comments

Comments
 (0)