]> git.baikalelectronics.ru Git - kernel.git/commitdiff
udp: Refactor udp_read_skb()
authorPeilin Ye <peilin.ye@bytedance.com>
Fri, 23 Sep 2022 04:59:13 +0000 (21:59 -0700)
committerJakub Kicinski <kuba@kernel.org>
Mon, 26 Sep 2022 18:00:19 +0000 (11:00 -0700)
Delete the unnecessary while loop in udp_read_skb() for readability.
Additionally, since recv_actor() cannot return a value greater than
skb->len (see sk_psock_verdict_recv()), remove the redundant check.

Suggested-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
Link: https://lore.kernel.org/r/343b5d8090a3eb764068e9f1d392939e2b423747.1663909008.git.peilin.ye@bytedance.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/udp.c

index 560d9eadeaa5805e4eeb416ff3b07a36bd746223..d63118ce5900678004aa12d3b72526a001be2e52 100644 (file)
@@ -1801,41 +1801,29 @@ EXPORT_SYMBOL(__skb_recv_udp);
 
 int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 {
-       int copied = 0;
-
-       while (1) {
-               struct sk_buff *skb;
-               int err, used;
-
-               skb = skb_recv_udp(sk, MSG_DONTWAIT, &err);
-               if (!skb)
-                       return err;
+       struct sk_buff *skb;
+       int err, copied;
 
-               if (udp_lib_checksum_complete(skb)) {
-                       __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS,
-                                       IS_UDPLITE(sk));
-                       __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS,
-                                       IS_UDPLITE(sk));
-                       atomic_inc(&sk->sk_drops);
-                       kfree_skb(skb);
-                       continue;
-               }
+try_again:
+       skb = skb_recv_udp(sk, MSG_DONTWAIT, &err);
+       if (!skb)
+               return err;
 
-               WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk));
-               used = recv_actor(sk, skb);
-               if (used <= 0) {
-                       if (!copied)
-                               copied = used;
-                       kfree_skb(skb);
-                       break;
-               } else if (used <= skb->len) {
-                       copied += used;
-               }
+       if (udp_lib_checksum_complete(skb)) {
+               int is_udplite = IS_UDPLITE(sk);
+               struct net *net = sock_net(sk);
 
+               __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, is_udplite);
+               __UDP_INC_STATS(net, UDP_MIB_INERRORS, is_udplite);
+               atomic_inc(&sk->sk_drops);
                kfree_skb(skb);
-               break;
+               goto try_again;
        }
 
+       WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk));
+       copied = recv_actor(sk, skb);
+       kfree_skb(skb);
+
        return copied;
 }
 EXPORT_SYMBOL(udp_read_skb);