@@ -129,22 +129,12 @@ static const struct ppp_channel_ops pppol2tp_chan_ops = {
129129
130130static const struct proto_ops pppol2tp_ops ;
131131
132- /* Retrieves the pppol2tp socket associated to a session.
133- * A reference is held on the returned socket, so this function must be paired
134- * with sock_put().
135- */
132+ /* Retrieves the pppol2tp socket associated to a session. */
136133static struct sock * pppol2tp_session_get_sock (struct l2tp_session * session )
137134{
138135 struct pppol2tp_session * ps = l2tp_session_priv (session );
139- struct sock * sk ;
140-
141- rcu_read_lock ();
142- sk = rcu_dereference (ps -> sk );
143- if (sk )
144- sock_hold (sk );
145- rcu_read_unlock ();
146136
147- return sk ;
137+ return rcu_dereference ( ps -> sk ) ;
148138}
149139
150140/* Helpers to obtain tunnel/session contexts from sockets.
@@ -206,14 +196,13 @@ static int pppol2tp_recvmsg(struct socket *sock, struct msghdr *msg,
206196
207197static void pppol2tp_recv (struct l2tp_session * session , struct sk_buff * skb , int data_len )
208198{
209- struct pppol2tp_session * ps = l2tp_session_priv (session );
210- struct sock * sk = NULL ;
199+ struct sock * sk ;
211200
212201 /* If the socket is bound, send it in to PPP's input queue. Otherwise
213202 * queue it on the session socket.
214203 */
215204 rcu_read_lock ();
216- sk = rcu_dereference ( ps -> sk );
205+ sk = pppol2tp_session_get_sock ( session );
217206 if (!sk )
218207 goto no_sock ;
219208
@@ -510,13 +499,14 @@ static void pppol2tp_show(struct seq_file *m, void *arg)
510499 struct l2tp_session * session = arg ;
511500 struct sock * sk ;
512501
502+ rcu_read_lock ();
513503 sk = pppol2tp_session_get_sock (session );
514504 if (sk ) {
515505 struct pppox_sock * po = pppox_sk (sk );
516506
517507 seq_printf (m , " interface %s\n" , ppp_dev_name (& po -> chan ));
518- sock_put (sk );
519508 }
509+ rcu_read_unlock ();
520510}
521511
522512static void pppol2tp_session_init (struct l2tp_session * session )
@@ -1529,6 +1519,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
15291519 port = ntohs (inet -> inet_sport );
15301520 }
15311521
1522+ rcu_read_lock ();
15321523 sk = pppol2tp_session_get_sock (session );
15331524 if (sk ) {
15341525 state = sk -> sk_state ;
@@ -1564,8 +1555,8 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
15641555 struct pppox_sock * po = pppox_sk (sk );
15651556
15661557 seq_printf (m , " interface %s\n" , ppp_dev_name (& po -> chan ));
1567- sock_put (sk );
15681558 }
1559+ rcu_read_unlock ();
15691560}
15701561
15711562static int pppol2tp_seq_show (struct seq_file * m , void * v )
0 commit comments