Skip to content

Commit 972692e

Browse files
committed
net: Add sk_set_socket() helper.
In order to more easily grep for all things that set sk->sk_socket, add sk_set_socket() helper inline function. Suggested (although only half-seriously) by Evgeniy Polyakov. Signed-off-by: David S. Miller <[email protected]>
1 parent 5bbc172 commit 972692e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/net/sock.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,11 @@ static inline void sock_put(struct sock *sk)
990990
extern int sk_receive_skb(struct sock *sk, struct sk_buff *skb,
991991
const int nested);
992992

993+
static inline void sk_set_socket(struct sock *sk, struct socket *sock)
994+
{
995+
sk->sk_socket = sock;
996+
}
997+
993998
/* Detach socket from process context.
994999
* Announce socket dead, detach it from wait queue and inode.
9951000
* Note that parent inode held reference count on this struct sock,
@@ -1001,7 +1006,7 @@ static inline void sock_orphan(struct sock *sk)
10011006
{
10021007
write_lock_bh(&sk->sk_callback_lock);
10031008
sock_set_flag(sk, SOCK_DEAD);
1004-
sk->sk_socket = NULL;
1009+
sk_set_socket(sk, NULL);
10051010
sk->sk_sleep = NULL;
10061011
write_unlock_bh(&sk->sk_callback_lock);
10071012
}
@@ -1011,7 +1016,7 @@ static inline void sock_graft(struct sock *sk, struct socket *parent)
10111016
write_lock_bh(&sk->sk_callback_lock);
10121017
sk->sk_sleep = &parent->wait;
10131018
parent->sk = sk;
1014-
sk->sk_socket = parent;
1019+
sk_set_socket(sk, parent);
10151020
security_sock_graft(sk, parent);
10161021
write_unlock_bh(&sk->sk_callback_lock);
10171022
}

net/core/sock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
10661066
* to be taken into account in all callers. -acme
10671067
*/
10681068
sk_refcnt_debug_inc(newsk);
1069-
newsk->sk_socket = NULL;
1069+
sk_set_socket(newsk, NULL);
10701070
newsk->sk_sleep = NULL;
10711071

10721072
if (newsk->sk_prot->sockets_allocated)
@@ -1702,7 +1702,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
17021702
sk->sk_rcvbuf = sysctl_rmem_default;
17031703
sk->sk_sndbuf = sysctl_wmem_default;
17041704
sk->sk_state = TCP_CLOSE;
1705-
sk->sk_socket = sock;
1705+
sk_set_socket(sk, sock);
17061706

17071707
sock_set_flag(sk, SOCK_ZAPPED);
17081708

0 commit comments

Comments
 (0)