Skip to content

Commit

Permalink
tcp: tcp_set_window_clamp() cleanup
Browse files Browse the repository at this point in the history
Remove one indentation level.

Use max_t() and clamp() macros.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250301201424.2046477-7-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Eric Dumazet authored and Jakub Kicinski committed Mar 3, 2025
1 parent 5282de1 commit 863a952
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3693,33 +3693,33 @@ EXPORT_SYMBOL(tcp_sock_set_keepcnt);

int tcp_set_window_clamp(struct sock *sk, int val)
{
u32 old_window_clamp, new_window_clamp;
struct tcp_sock *tp = tcp_sk(sk);

if (!val) {
if (sk->sk_state != TCP_CLOSE)
return -EINVAL;
WRITE_ONCE(tp->window_clamp, 0);
} else {
u32 new_rcv_ssthresh, old_window_clamp = tp->window_clamp;
u32 new_window_clamp = val < SOCK_MIN_RCVBUF / 2 ?
SOCK_MIN_RCVBUF / 2 : val;
return 0;
}

if (new_window_clamp == old_window_clamp)
return 0;
old_window_clamp = tp->window_clamp;
new_window_clamp = max_t(int, SOCK_MIN_RCVBUF / 2, val);

WRITE_ONCE(tp->window_clamp, new_window_clamp);
if (new_window_clamp < old_window_clamp) {
/* need to apply the reserved mem provisioning only
* when shrinking the window clamp
*/
__tcp_adjust_rcv_ssthresh(sk, tp->window_clamp);
if (new_window_clamp == old_window_clamp)
return 0;

} else {
new_rcv_ssthresh = min(tp->rcv_wnd, tp->window_clamp);
tp->rcv_ssthresh = max(new_rcv_ssthresh,
tp->rcv_ssthresh);
}
}
WRITE_ONCE(tp->window_clamp, new_window_clamp);

/* Need to apply the reserved mem provisioning only
* when shrinking the window clamp.
*/
if (new_window_clamp < old_window_clamp)
__tcp_adjust_rcv_ssthresh(sk, new_window_clamp);
else
tp->rcv_ssthresh = clamp(new_window_clamp,
tp->rcv_ssthresh,
tp->rcv_wnd);
return 0;
}

Expand Down

0 comments on commit 863a952

Please sign in to comment.