net: remove obsolete WARN_ON(refcount_read(&sk->sk_refcnt) == 1)
Subsystems (5)
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.
--- 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
@@ -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
@@ -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
@@ -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
Quoted 10 lines · Eric Dumazet
sk->sk_refcnthas been converted torefcount_tin 2017.
__sock_put(sk)beingrefcount_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 genericrefcount_dec()check.Signed-off-by Eric Dumazet <[email protected]>
Thanks for catching this!
Quoted 9 lines · Eric Dumazet
sk->sk_refcnthas been converted torefcount_tin 2017.
__sock_put(sk)beingrefcount_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 genericrefcount_dec()check.Signed-off-by Eric Dumazet <[email protected]>
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
@@ -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!
Quoted 15 lines · luoxuanqiang
Quoted 9 lines · Eric Dumazet
sk->sk_refcnthas been converted torefcount_tin 2017.
__sock_put(sk)beingrefcount_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 genericrefcount_dec()check.Signed-off-by Eric Dumazet <[email protected]>Reviewed-by Xuanqiang Luo<[email protected]>
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.
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_refcnthas been converted torefcount_tin 2017.
__sock_put(sk)beingrefcount_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 genericrefcount_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