]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)
authorEric Dumazet <edumazet@google.com>
Tue, 14 Oct 2025 14:06:05 +0000 (14:06 +0000)
committerJakub Kicinski <kuba@kernel.org>
Thu, 16 Oct 2025 00:18:38 +0000 (17:18 -0700)
sk->sk_refcnt has been converted to refcount_t in 2017.

__sock_put(sk) being refcount_dec(&sk->sk_refcnt), it will complain
loudly if the current refcnt is 1 (or less) in a non racy way.

We can remove four WARN_ON() in favor of the generic refcount_dec()
check.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Xuanqiang Luo<luoxuanqiang@kylinos.cn>
Link: https://patch.msgid.link/20251014140605.2982703-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/sock.h
net/netlink/af_netlink.c
net/tipc/socket.c

index f0d00928db9e9241a2f2b9f193725bda9f5c0b69..30ac2eb4ef9bf73743e3dc9e66c6c3059f34964e 100644 (file)
@@ -830,11 +830,9 @@ static inline bool sk_del_node_init(struct sock *sk)
 {
        bool rc = __sk_del_node_init(sk);
 
-       if (rc) {
-               /* paranoid for a while -acme */
-               WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
+       if (rc)
                __sock_put(sk);
-       }
+
        return rc;
 }
 #define sk_del_node_init_rcu(sk)       sk_del_node_init(sk)
@@ -852,11 +850,9 @@ static inline bool sk_nulls_del_node_init_rcu(struct sock *sk)
 {
        bool rc = __sk_nulls_del_node_init_rcu(sk);
 
-       if (rc) {
-               /* paranoid for a while -acme */
-               WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
+       if (rc)
                __sock_put(sk);
-       }
+
        return rc;
 }
 
index 2b46c0cd752a313ad95cf17c46237883d6b85293..687a84c48882a61e3c9f3fddad8c718fa4120bb2 100644 (file)
@@ -596,10 +596,8 @@ static void netlink_remove(struct sock *sk)
 
        table = &nl_table[sk->sk_protocol];
        if (!rhashtable_remove_fast(&table->hash, &nlk_sk(sk)->node,
-                                   netlink_rhashtable_params)) {
-               WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
+                                   netlink_rhashtable_params))
                __sock_put(sk);
-       }
 
        netlink_table_grab();
        if (nlk_sk(sk)->subscriptions) {
index 1574a83384f88533cfab330c559512d5878bf0aa..bc614a1f019c27e38a9353b742654b2c2bbae2ba 100644 (file)
@@ -3031,10 +3031,8 @@ static void tipc_sk_remove(struct tipc_sock *tsk)
        struct sock *sk = &tsk->sk;
        struct tipc_net *tn = net_generic(sock_net(sk), tipc_net_id);
 
-       if (!rhashtable_remove_fast(&tn->sk_rht, &tsk->node, tsk_rht_params)) {
-               WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
+       if (!rhashtable_remove_fast(&tn->sk_rht, &tsk->node, tsk_rht_params))
                __sock_put(sk);
-       }
 }
 
 static const struct rhashtable_params tsk_rht_params = {