Message ID | 20241213092152.14057-10-kuniyu@amazon.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | treewide: socket: Clean up sock_create() and friends. | expand |
diff --git a/net/core/sock.c b/net/core/sock.c index 8546d97cc6ec..11aa6d8c0cdd 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2224,9 +2224,12 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority, * why we need sk_prot_creator -acme */ sk->sk_prot = sk->sk_prot_creator = prot; + + DEBUG_NET_WARN_ON_ONCE(!kern && !hold_net); sk->sk_kern_sock = kern; sock_lock_init(sk); - sk->sk_net_refcnt = kern ? 0 : 1; + + sk->sk_net_refcnt = hold_net; if (likely(sk->sk_net_refcnt)) { get_net_track(net, &sk->ns_tracker, priority); sock_inuse_add(net, 1);
We will introduce a new API to create a kernel socket with netns refcnt held. sk->sk_net_refcnt was set to 0 when kern was 1 in sk_alloc(). Now we have the hold_net flag in sk_alloc(). Let's set it to sk->sk_net_refcnt and add an assertion to catch only one illegal pattern. No functional change is introduced for now because currently hold_net == !kern. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> --- net/core/sock.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)