Skip to content

Commit

Permalink
af_unix: Use msg->{msg_name,msg_namelen} in unix_dgram_sendmsg().
Browse files Browse the repository at this point in the history
In unix_dgram_sendmsg(), we use a local variable sunaddr pointing
NULL or msg->msg_name based on msg->msg_namelen.

Let's remove sunaddr and simplify the usage.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Kuniyuki Iwashima authored and Paolo Abeni committed Dec 17, 2024
1 parent f4dd631 commit 3c05329
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,6 @@ static void scm_stat_del(struct sock *sk, struct sk_buff *skb)
static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
size_t len)
{
DECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, msg->msg_name);
struct sock *sk = sock->sk, *other = NULL;
struct unix_sock *u = unix_sk(sk);
struct scm_cookie scm;
Expand All @@ -1984,7 +1983,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
}

if (msg->msg_namelen) {
err = unix_validate_addr(sunaddr, msg->msg_namelen);
err = unix_validate_addr(msg->msg_name, msg->msg_namelen);
if (err)
goto out;

Expand All @@ -1995,7 +1994,6 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
if (err)
goto out;
} else {
sunaddr = NULL;
other = unix_peer_get(sk);
if (!other) {
err = -ENOTCONN;
Expand Down Expand Up @@ -2046,8 +2044,8 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,

restart:
if (!other) {
other = unix_find_other(sock_net(sk), sunaddr, msg->msg_namelen,
sk->sk_type);
other = unix_find_other(sock_net(sk), msg->msg_name,
msg->msg_namelen, sk->sk_type);
if (IS_ERR(other)) {
err = PTR_ERR(other);
other = NULL;
Expand Down Expand Up @@ -2101,7 +2099,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
} else {
unix_state_unlock(sk);

if (!sunaddr)
if (!msg->msg_namelen)
err = -ECONNRESET;
}

Expand Down

0 comments on commit 3c05329

Please sign in to comment.