Skip to content

Commit

Permalink
af_unix: Reuse out_pipe label in unix_stream_sendmsg().
Browse files Browse the repository at this point in the history
This is a follow-up of commit d460b04 ("af_unix: Clean up
error paths in unix_stream_sendmsg().").

If we initialise skb with NULL in unix_stream_sendmsg(), we can
reuse the existing out_pipe label for the SEND_SHUTDOWN check.

Let's rename it and adjust the existing label as out_pipe_lock.

While at it, size and data_len are moved to the while loop scope.

Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250116053441.5758-9-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Kuniyuki Iwashima authored and Jakub Kicinski committed Jan 20, 2025
1 parent b3e365b commit 3b2d40d
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -2238,13 +2238,11 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
size_t len)
{
struct sock *sk = sock->sk;
struct sk_buff *skb = NULL;
struct sock *other = NULL;
int err, size;
struct sk_buff *skb;
int sent = 0;
struct scm_cookie scm;
bool fds_sent = false;
int data_len;
int err, sent = 0;

err = scm_send(sock, msg, &scm, false);
if (err < 0)
Expand Down Expand Up @@ -2273,16 +2271,12 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
}
}

if (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN) {
if (!(msg->msg_flags & MSG_NOSIGNAL))
send_sig(SIGPIPE, current, 0);

err = -EPIPE;
goto out_err;
}
if (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN)
goto out_pipe;

while (sent < len) {
size = len - sent;
int size = len - sent;
int data_len;

if (unlikely(msg->msg_flags & MSG_SPLICE_PAGES)) {
skb = sock_alloc_send_pskb(sk, 0, 0,
Expand Down Expand Up @@ -2335,7 +2329,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,

if (sock_flag(other, SOCK_DEAD) ||
(other->sk_shutdown & RCV_SHUTDOWN))
goto out_pipe;
goto out_pipe_unlock;

maybe_add_creds(skb, sock, other);
scm_stat_add(other, skb);
Expand All @@ -2358,8 +2352,9 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,

return sent;

out_pipe:
out_pipe_unlock:
unix_state_unlock(other);
out_pipe:
if (!sent && !(msg->msg_flags & MSG_NOSIGNAL))
send_sig(SIGPIPE, current, 0);
err = -EPIPE;
Expand Down

0 comments on commit 3b2d40d

Please sign in to comment.