Commit d6e3b27c authored by Peilin Ye's avatar Peilin Ye Committed by Jakub Kicinski

af_unix: Refactor unix_read_skb()

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: default avatarCong Wang <cong.wang@bytedance.com>
Signed-off-by: default avatarPeilin Ye <peilin.ye@bytedance.com>
Link: https://lore.kernel.org/r/7009141683ad6cd3785daced3e4a80ba0eb773b5.1663909008.git.peilin.ye@bytedance.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 31f1fbcb
...@@ -2536,32 +2536,18 @@ static int unix_dgram_recvmsg(struct socket *sock, struct msghdr *msg, size_t si ...@@ -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) static int unix_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
{ {
int copied = 0; struct unix_sock *u = unix_sk(sk);
struct sk_buff *skb;
while (1) { int err, copied;
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;
used = recv_actor(sk, skb); mutex_lock(&u->iolock);
if (used <= 0) { skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err);
if (!copied) mutex_unlock(&u->iolock);
copied = used; if (!skb)
kfree_skb(skb); return err;
break;
} else if (used <= skb->len) {
copied += used;
}
kfree_skb(skb); copied = recv_actor(sk, skb);
break; kfree_skb(skb);
}
return copied; return copied;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment