Skip to content

Commit d93b8a6

Browse files
j-c-hdavem330
authored andcommitted
l2tp: cleanup eth/ppp pseudowire setup code
l2tp eth/ppp pseudowire setup/cleanup uses kfree() in some error paths. Drop the refcount instead such that the session object is always freed when the refcount reaches 0. Signed-off-by: James Chapman <[email protected]> Signed-off-by: Tom Parkin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0aa4557 commit d93b8a6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

net/l2tp/l2tp_eth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static int l2tp_eth_create(struct net *net, struct l2tp_tunnel *tunnel,
322322
l2tp_session_dec_refcount(session);
323323
free_netdev(dev);
324324
err_sess:
325-
kfree(session);
325+
l2tp_session_dec_refcount(session);
326326
err:
327327
return rc;
328328
}

net/l2tp/l2tp_ppp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
770770
goto end;
771771
}
772772

773+
drop_refcnt = true;
774+
773775
pppol2tp_session_init(session);
774776
ps = l2tp_session_priv(session);
775777
l2tp_session_inc_refcount(session);
@@ -778,10 +780,10 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
778780
error = l2tp_session_register(session, tunnel);
779781
if (error < 0) {
780782
mutex_unlock(&ps->sk_lock);
781-
kfree(session);
783+
l2tp_session_dec_refcount(session);
782784
goto end;
783785
}
784-
drop_refcnt = true;
786+
785787
new_session = true;
786788
}
787789

@@ -875,7 +877,7 @@ static int pppol2tp_session_create(struct net *net, struct l2tp_tunnel *tunnel,
875877
return 0;
876878

877879
err_sess:
878-
kfree(session);
880+
l2tp_session_dec_refcount(session);
879881
err:
880882
return error;
881883
}

0 commit comments

Comments
 (0)