inet: inet_twsk_deschedule factorization
authorEric Dumazet <edumazet@google.com>
Wed, 8 Jul 2015 21:28:30 +0000 (14:28 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 9 Jul 2015 22:12:20 +0000 (15:12 -0700)
inet_twsk_deschedule() calls are followed by inet_twsk_put().

Only particular case is in inet_twsk_purge() but there is no point
to defer the inet_twsk_put() after re-enabling BH.

Lets rename inet_twsk_deschedule() to inet_twsk_deschedule_put()
and move the inet_twsk_put() inside.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/inet_timewait_sock.h
net/ipv4/inet_hashtables.c
net/ipv4/inet_timewait_sock.c
net/ipv4/tcp_ipv4.c
net/ipv4/tcp_minisocks.c
net/ipv6/inet6_hashtables.c
net/ipv6/tcp_ipv6.c
net/netfilter/xt_TPROXY.c

index 96f52a4711c8b799839c722af403a03e684de476..879d6e5a973b4ae1af54d6b0c6103c02ee774991 100644 (file)
@@ -111,7 +111,7 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
                           struct inet_hashinfo *hashinfo);
 
 void inet_twsk_schedule(struct inet_timewait_sock *tw, const int timeo);
-void inet_twsk_deschedule(struct inet_timewait_sock *tw);
+void inet_twsk_deschedule_put(struct inet_timewait_sock *tw);
 
 void inet_twsk_purge(struct inet_hashinfo *hashinfo,
                     struct inet_timewait_death_row *twdr, int family);
index e58840330da7ebfa4b6c9ad3b37534b9aa470095..f8b3701a6c3c66dafe8d9a1e01aaf4836e88ec71 100644 (file)
@@ -380,8 +380,7 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
                *twp = tw;
        } else if (tw) {
                /* Silly. Should hash-dance instead... */
-               inet_twsk_deschedule(tw);
-               inet_twsk_put(tw);
+               inet_twsk_deschedule_put(tw);
        }
        return 0;
 
@@ -558,10 +557,8 @@ ok:
                        inet_twsk_bind_unhash(tw, hinfo);
                spin_unlock(&head->lock);
 
-               if (tw) {
-                       inet_twsk_deschedule(tw);
-                       inet_twsk_put(tw);
-               }
+               if (tw)
+                       inet_twsk_deschedule_put(tw);
 
                ret = 0;
                goto out;
index 92cd4d50404eb168f95ca82b717ef5423a4aa5cb..ae22cc24fbe89b32be1f2142450c198e78026851 100644 (file)
@@ -205,13 +205,17 @@ EXPORT_SYMBOL_GPL(inet_twsk_alloc);
  * tcp_input.c to verify this.
  */
 
-/* This is for handling early-kills of TIME_WAIT sockets. */
-void inet_twsk_deschedule(struct inet_timewait_sock *tw)
+/* This is for handling early-kills of TIME_WAIT sockets.
+ * Warning : consume reference.
+ * Caller should not access tw anymore.
+ */
+void inet_twsk_deschedule_put(struct inet_timewait_sock *tw)
 {
        if (del_timer_sync(&tw->tw_timer))
                inet_twsk_kill(tw);
+       inet_twsk_put(tw);
 }
-EXPORT_SYMBOL(inet_twsk_deschedule);
+EXPORT_SYMBOL(inet_twsk_deschedule_put);
 
 void inet_twsk_schedule(struct inet_timewait_sock *tw, const int timeo)
 {
@@ -281,9 +285,8 @@ restart:
 
                        rcu_read_unlock();
                        local_bh_disable();
-                       inet_twsk_deschedule(tw);
+                       inet_twsk_deschedule_put(tw);
                        local_bh_enable();
-                       inet_twsk_put(tw);
                        goto restart_rcu;
                }
                /* If the nulls value we got at the end of this lookup is
index d7d4c2b79cf2f516f9e3f62c6fe4415e9bc137a0..486ba96ae91a7f1553bb6d6025e14fc0da2ba3a3 100644 (file)
@@ -1683,8 +1683,7 @@ do_time_wait:
                                                        iph->daddr, th->dest,
                                                        inet_iif(skb));
                if (sk2) {
-                       inet_twsk_deschedule(inet_twsk(sk));
-                       inet_twsk_put(inet_twsk(sk));
+                       inet_twsk_deschedule_put(inet_twsk(sk));
                        sk = sk2;
                        goto process;
                }
index 4bc00cb79e603553076adf750712377586f4b2fb..6d8795b066aca708df47de3c9211f36bee5eb1d4 100644 (file)
@@ -147,8 +147,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
                if (!th->fin ||
                    TCP_SKB_CB(skb)->end_seq != tcptw->tw_rcv_nxt + 1) {
 kill_with_rst:
-                       inet_twsk_deschedule(tw);
-                       inet_twsk_put(tw);
+                       inet_twsk_deschedule_put(tw);
                        return TCP_TW_RST;
                }
 
@@ -198,8 +197,7 @@ kill_with_rst:
                         */
                        if (sysctl_tcp_rfc1337 == 0) {
 kill:
-                               inet_twsk_deschedule(tw);
-                               inet_twsk_put(tw);
+                               inet_twsk_deschedule_put(tw);
                                return TCP_TW_SUCCESS;
                        }
                }
index a237398aa2b491ba4398f2dea83989e5a526f028..6ac8dad0138a6b41395f306bffc2d9b47d8d91bc 100644 (file)
@@ -243,8 +243,7 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
                *twp = tw;
        } else if (tw) {
                /* Silly. Should hash-dance instead... */
-               inet_twsk_deschedule(tw);
-               inet_twsk_put(tw);
+               inet_twsk_deschedule_put(tw);
        }
        return 0;
 
index 6748c4277affad71cd721e3a985af10c31c047ad..d540846a1a79e1f263d593343b6d240ad780527a 100644 (file)
@@ -1481,8 +1481,7 @@ do_time_wait:
                                            ntohs(th->dest), tcp_v6_iif(skb));
                if (sk2) {
                        struct inet_timewait_sock *tw = inet_twsk(sk);
-                       inet_twsk_deschedule(tw);
-                       inet_twsk_put(tw);
+                       inet_twsk_deschedule_put(tw);
                        sk = sk2;
                        tcp_v6_restore_cb(skb);
                        goto process;
index cca96cec1b689fcd104e273a64db6eda44171beb..d0c96c5ae29aa84057e93a5d9796014dca4c52e8 100644 (file)
@@ -272,8 +272,7 @@ tproxy_handle_time_wait4(struct sk_buff *skb, __be32 laddr, __be16 lport,
                                            hp->source, lport ? lport : hp->dest,
                                            skb->dev, NFT_LOOKUP_LISTENER);
                if (sk2) {
-                       inet_twsk_deschedule(inet_twsk(sk));
-                       inet_twsk_put(inet_twsk(sk));
+                       inet_twsk_deschedule_put(inet_twsk(sk));
                        sk = sk2;
                }
        }
@@ -437,8 +436,7 @@ tproxy_handle_time_wait6(struct sk_buff *skb, int tproto, int thoff,
                                            tgi->lport ? tgi->lport : hp->dest,
                                            skb->dev, NFT_LOOKUP_LISTENER);
                if (sk2) {
-                       inet_twsk_deschedule(inet_twsk(sk));
-                       inet_twsk_put(inet_twsk(sk));
+                       inet_twsk_deschedule_put(inet_twsk(sk));
                        sk = sk2;
                }
        }