Commit aed26f55 authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by Jakub Kicinski

af_unix: Return an error as a pointer in unix_find_other().

We can return an error as a pointer and need not pass an additional
argument to unix_find_other().
Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.co.jp>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent fa39ef0e
...@@ -951,7 +951,7 @@ static int unix_release(struct socket *sock) ...@@ -951,7 +951,7 @@ static int unix_release(struct socket *sock)
} }
static struct sock *unix_find_bsd(struct net *net, struct sockaddr_un *sunaddr, static struct sock *unix_find_bsd(struct net *net, struct sockaddr_un *sunaddr,
int type, int *error) int type)
{ {
struct inode *inode; struct inode *inode;
struct path path; struct path path;
...@@ -990,23 +990,20 @@ static struct sock *unix_find_bsd(struct net *net, struct sockaddr_un *sunaddr, ...@@ -990,23 +990,20 @@ static struct sock *unix_find_bsd(struct net *net, struct sockaddr_un *sunaddr,
path_put: path_put:
path_put(&path); path_put(&path);
fail: fail:
*error = err; return ERR_PTR(err);
return NULL;
} }
static struct sock *unix_find_abstract(struct net *net, static struct sock *unix_find_abstract(struct net *net,
struct sockaddr_un *sunaddr, struct sockaddr_un *sunaddr,
int addr_len, int type, int addr_len, int type,
unsigned int hash, int *error) unsigned int hash)
{ {
struct dentry *dentry; struct dentry *dentry;
struct sock *sk; struct sock *sk;
sk = unix_find_socket_byname(net, sunaddr, addr_len, type ^ hash); sk = unix_find_socket_byname(net, sunaddr, addr_len, type ^ hash);
if (!sk) { if (!sk)
*error = -ECONNREFUSED; return ERR_PTR(-ECONNREFUSED);
return NULL;
}
dentry = unix_sk(sk)->path.dentry; dentry = unix_sk(sk)->path.dentry;
if (dentry) if (dentry)
...@@ -1018,15 +1015,14 @@ static struct sock *unix_find_abstract(struct net *net, ...@@ -1018,15 +1015,14 @@ static struct sock *unix_find_abstract(struct net *net,
static struct sock *unix_find_other(struct net *net, static struct sock *unix_find_other(struct net *net,
struct sockaddr_un *sunaddr, struct sockaddr_un *sunaddr,
int addr_len, int type, int addr_len, int type,
unsigned int hash, int *error) unsigned int hash)
{ {
struct sock *sk; struct sock *sk;
if (sunaddr->sun_path[0]) if (sunaddr->sun_path[0])
sk = unix_find_bsd(net, sunaddr, type, error); sk = unix_find_bsd(net, sunaddr, type);
else else
sk = unix_find_abstract(net, sunaddr, addr_len, type, hash, sk = unix_find_abstract(net, sunaddr, addr_len, type, hash);
error);
return sk; return sk;
} }
...@@ -1263,9 +1259,11 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1263,9 +1259,11 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
} }
restart: restart:
other = unix_find_other(net, sunaddr, alen, sock->type, hash, &err); other = unix_find_other(net, sunaddr, alen, sock->type, hash);
if (!other) if (IS_ERR(other)) {
err = PTR_ERR(other);
goto out; goto out;
}
unix_state_double_lock(sk, other); unix_state_double_lock(sk, other);
...@@ -1395,9 +1393,12 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1395,9 +1393,12 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
restart: restart:
/* Find listening sock. */ /* Find listening sock. */
other = unix_find_other(net, sunaddr, addr_len, sk->sk_type, hash, &err); other = unix_find_other(net, sunaddr, addr_len, sk->sk_type, hash);
if (!other) if (IS_ERR(other)) {
err = PTR_ERR(other);
other = NULL;
goto out; goto out;
}
/* Latch state of peer */ /* Latch state of peer */
unix_state_lock(other); unix_state_lock(other);
...@@ -1866,9 +1867,12 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -1866,9 +1867,12 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
goto out_free; goto out_free;
other = unix_find_other(net, sunaddr, namelen, sk->sk_type, other = unix_find_other(net, sunaddr, namelen, sk->sk_type,
hash, &err); hash);
if (other == NULL) if (IS_ERR(other)) {
err = PTR_ERR(other);
other = NULL;
goto out_free; goto out_free;
}
} }
if (sk_filter(other, skb) < 0) { if (sk_filter(other, skb) < 0) {
......
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