Skip to contentSkip to conversation

net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)

PATCH Applied Eric Dumazet 4 participants 5 messages Oct 14, 2025 – Oct 16, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)

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.

Cc Xuanqiang Luo <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
---
 include/net/sock.h       | 12 ++++--------
 net/netlink/af_netlink.c |  4 +---
 net/tipc/socket.c        |  4 +---
 3 files changed, 6 insertions(+), 14 deletions(-)
include/net/sock.h +4 -8
index 60bcb13f045c..596302bffedf 100644
@@ -828,11 +828,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)
@@ -850,11 +848,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;
 }
 
net/netlink/af_netlink.c +1 -3
index 2b46c0cd752a..687a84c48882 100644
@@ -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) {
net/tipc/socket.c +1 -3
index 1574a83384f8..bc614a1f019c 100644
@@ -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 = {
Signature · 1 line
2.51.0.788.g6d19910ace-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Eric Dumazet

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.

Thanks for catching this!

Reviewed-by Xuanqiang Luo on v1 1/1
#2 lore raw
In reply to Eric Dumazet
Quoted 9 lines · Eric Dumazet

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.

Dear Eric,

Following your line of thought, I found there's also a point in btrfs that needs modification.

Would you like to modify it together? Though it has nothing to do with socket, or shall I modify it separately later?

fs/btrfs/transaction.c +0 -0
index 89ae0c7a610a..485bef0ba419 100644
@@ -138,7 +138,6 @@ static const unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = {

 void btrfs_put_transaction(struct btrfs_transaction *transaction) {
-       WARN_ON(refcount_read(&transaction->use_count) == 0); if (refcount_dec_and_test(&transaction->use_count)) { BUG_ON(!list_empty(&transaction->list)); WARN_ON(!xa_empty(&transaction->delayed_refs.head_refs));

Thanks!

#3 lore raw
Quoted 15 lines · luoxuanqiang
Quoted 9 lines · Eric Dumazet

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.

Quoted 7 lines

Dear Eric,

Following your line of thought, I found there's also a point in btrfs that needs modification.

Would you like to modify it together? Though it has nothing to do with socket, or shall I modify it separately later?

I removed stuff around sk_refcnt only.

If you want, please send a patch to the appropriate lists and maintainers.

#4 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Tue, 14 Oct 2025 14:06:05 +0000 you wrote:

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.

[...]

Here is the summary with links:
- [net-next] net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)

    https://git.kernel.org/netdev/net-next/c/e5b670e5439b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html