]> git.baikalelectronics.ru Git - kernel.git/commitdiff
af_unix: Refactor unix_read_skb()
authorPeilin Ye <peilin.ye@bytedance.com>
Fri, 23 Sep 2022 04:59:26 +0000 (21:59 -0700)
committerJakub Kicinski <kuba@kernel.org>
Mon, 26 Sep 2022 18:00:19 +0000 (11:00 -0700)
Similar to udp_read_skb(), delete the unnecessary while loop in
unix_read_skb() for readability.  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/7009141683ad6cd3785daced3e4a80ba0eb773b5.1663909008.git.peilin.ye@bytedance.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/unix/af_unix.c

index dea2972c8178c98b3d20fba0f3d3523bc8e42398..c955c7253d4b390bf10ab9d8f72b9095e6bcd0a5 100644 (file)
@@ -2536,32 +2536,18 @@ static int unix_dgram_recvmsg(struct socket *sock, struct msghdr *msg, size_t si
 
 static int unix_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 {
-       int copied = 0;
-
-       while (1) {
-               struct unix_sock *u = unix_sk(sk);
-               struct sk_buff *skb;
-               int used, err;
-
-               mutex_lock(&u->iolock);
-               skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err);
-               mutex_unlock(&u->iolock);
-               if (!skb)
-                       return err;
+       struct unix_sock *u = unix_sk(sk);
+       struct sk_buff *skb;
+       int err, copied;
 
-               used = recv_actor(sk, skb);
-               if (used <= 0) {
-                       if (!copied)
-                               copied = used;
-                       kfree_skb(skb);
-                       break;
-               } else if (used <= skb->len) {
-                       copied += used;
-               }
+       mutex_lock(&u->iolock);
+       skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err);
+       mutex_unlock(&u->iolock);
+       if (!skb)
+               return err;
 
-               kfree_skb(skb);
-               break;
-       }
+       copied = recv_actor(sk, skb);
+       kfree_skb(skb);
 
        return copied;
 }