Skip to content

Commit 3b2d40d

Browse files
q2venkuba-moo
authored andcommitted
af_unix: Reuse out_pipe label in unix_stream_sendmsg().
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 <[email protected]> Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent b3e365b commit 3b2d40d

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

net/unix/af_unix.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,13 +2238,11 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
22382238
size_t len)
22392239
{
22402240
struct sock *sk = sock->sk;
2241+
struct sk_buff *skb = NULL;
22412242
struct sock *other = NULL;
2242-
int err, size;
2243-
struct sk_buff *skb;
2244-
int sent = 0;
22452243
struct scm_cookie scm;
22462244
bool fds_sent = false;
2247-
int data_len;
2245+
int err, sent = 0;
22482246

22492247
err = scm_send(sock, msg, &scm, false);
22502248
if (err < 0)
@@ -2273,16 +2271,12 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
22732271
}
22742272
}
22752273

2276-
if (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN) {
2277-
if (!(msg->msg_flags & MSG_NOSIGNAL))
2278-
send_sig(SIGPIPE, current, 0);
2279-
2280-
err = -EPIPE;
2281-
goto out_err;
2282-
}
2274+
if (READ_ONCE(sk->sk_shutdown) & SEND_SHUTDOWN)
2275+
goto out_pipe;
22832276

22842277
while (sent < len) {
2285-
size = len - sent;
2278+
int size = len - sent;
2279+
int data_len;
22862280

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

23362330
if (sock_flag(other, SOCK_DEAD) ||
23372331
(other->sk_shutdown & RCV_SHUTDOWN))
2338-
goto out_pipe;
2332+
goto out_pipe_unlock;
23392333

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

23592353
return sent;
23602354

2361-
out_pipe:
2355+
out_pipe_unlock:
23622356
unix_state_unlock(other);
2357+
out_pipe:
23632358
if (!sent && !(msg->msg_flags & MSG_NOSIGNAL))
23642359
send_sig(SIGPIPE, current, 0);
23652360
err = -EPIPE;

0 commit comments

Comments
 (0)