Skip to content

Commit

Permalink
af_unix: Refactor unix_read_skb()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Peilin Ye <[email protected]>
Link: https://lore.kernel.org/r/7009141683ad6cd3785daced3e4a80ba0eb773b5.1663909008.git.peilin.ye@bytedance.com
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
peilin-ye authored and kuba-moo committed Sep 26, 2022
1 parent 31f1fbc commit d6e3b27
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d6e3b27

Please sign in to comment.