Skip to content

Commit

Permalink
tcp: refactor tcp_read_skb() a bit
Browse files Browse the repository at this point in the history
As tcp_read_skb() only reads one skb at a time, the while loop is
unnecessary, we can turn it into an if. This also simplifies the
code logic.

Cc: Eric Dumazet <edumazet@google.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Cong Wang authored and Jakub Kicinski committed Aug 18, 2022
1 parent c457985 commit a868882
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1761,25 +1761,17 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
if (sk->sk_state == TCP_LISTEN)
return -ENOTCONN;

while ((skb = tcp_recv_skb(sk, seq, &offset)) != NULL) {
int used;

__skb_unlink(skb, &sk->sk_receive_queue);
WARN_ON(!skb_set_owner_sk_safe(skb, sk));
used = recv_actor(sk, skb);
if (used <= 0) {
if (!copied)
copied = used;
break;
}
seq += used;
copied += used;
skb = tcp_recv_skb(sk, seq, &offset);
if (!skb)
return 0;

if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) {
__skb_unlink(skb, &sk->sk_receive_queue);
WARN_ON(!skb_set_owner_sk_safe(skb, sk));
copied = recv_actor(sk, skb);
if (copied > 0) {
seq += copied;
if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
++seq;
break;
}
break;
}
consume_skb(skb);
WRITE_ONCE(tp->copied_seq, seq);
Expand Down

0 comments on commit a868882

Please sign in to comment.