aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-12-07 07:03:55 -0500
committerDavid S. Miller <davem@davemloft.net>2010-12-08 15:34:08 -0500
commitad9f4f50fe9288bbe65b7dfd76d8820afac6a24c (patch)
treef3f3100da8d042607bbbab31c1f8a060ba2b5f15 /net/ipv4
parentc7757fdb41dfcf6add9f8a4576eb85aa5e77a4eb (diff)
tcp: avoid a possible divide by zero
sysctl_tcp_tso_win_divisor might be set to zero while one cpu runs in tcp_tso_should_defer(). Make sure we dont allow a divide by zero by reading sysctl_tcp_tso_win_divisor exactly once. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/tcp_output.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 3c59ab42df2b..0d4a3cebfb46 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -1512,6 +1512,7 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
1512 struct tcp_sock *tp = tcp_sk(sk); 1512 struct tcp_sock *tp = tcp_sk(sk);
1513 const struct inet_connection_sock *icsk = inet_csk(sk); 1513 const struct inet_connection_sock *icsk = inet_csk(sk);
1514 u32 send_win, cong_win, limit, in_flight; 1514 u32 send_win, cong_win, limit, in_flight;
1515 int win_divisor;
1515 1516
1516 if (TCP_SKB_CB(skb)->flags & TCPHDR_FIN) 1517 if (TCP_SKB_CB(skb)->flags & TCPHDR_FIN)
1517 goto send_now; 1518 goto send_now;
@@ -1543,13 +1544,14 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
1543 if ((skb != tcp_write_queue_tail(sk)) && (limit >= skb->len)) 1544 if ((skb != tcp_write_queue_tail(sk)) && (limit >= skb->len))
1544 goto send_now; 1545 goto send_now;
1545 1546
1546 if (sysctl_tcp_tso_win_divisor) { 1547 win_divisor = ACCESS_ONCE(sysctl_tcp_tso_win_divisor);
1548 if (win_divisor) {
1547 u32 chunk = min(tp->snd_wnd, tp->snd_cwnd * tp->mss_cache); 1549 u32 chunk = min(tp->snd_wnd, tp->snd_cwnd * tp->mss_cache);
1548 1550
1549 /* If at least some fraction of a window is available, 1551 /* If at least some fraction of a window is available,
1550 * just use it. 1552 * just use it.
1551 */ 1553 */
1552 chunk /= sysctl_tcp_tso_win_divisor; 1554 chunk /= win_divisor;
1553 if (limit >= chunk) 1555 if (limit >= chunk)
1554 goto send_now; 1556 goto send_now;
1555 } else { 1557 } else {