Commit 340c3d33 authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by David S. Miller

af_unix: Clean up some sock_net() uses.

Some functions define a net pointer only for one-shot use.  Others call
sock_net() redundantly even when a net pointer is available.  Let's fix
these and make the code simpler.
Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ffd3018b
...@@ -932,7 +932,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern, ...@@ -932,7 +932,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern,
memset(&u->scm_stat, 0, sizeof(struct scm_stat)); memset(&u->scm_stat, 0, sizeof(struct scm_stat));
unix_insert_unbound_socket(sk); unix_insert_unbound_socket(sk);
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); sock_prot_inuse_add(net, sk->sk_prot, 1);
return sk; return sk;
...@@ -1293,9 +1293,8 @@ static void unix_state_double_unlock(struct sock *sk1, struct sock *sk2) ...@@ -1293,9 +1293,8 @@ static void unix_state_double_unlock(struct sock *sk1, struct sock *sk2)
static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr, static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
int alen, int flags) int alen, int flags)
{ {
struct sock *sk = sock->sk;
struct net *net = sock_net(sk);
struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr; struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
struct sock *sk = sock->sk;
struct sock *other; struct sock *other;
int err; int err;
...@@ -1316,7 +1315,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1316,7 +1315,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
} }
restart: restart:
other = unix_find_other(net, sunaddr, alen, sock->type); other = unix_find_other(sock_net(sk), sunaddr, alen, sock->type);
if (IS_ERR(other)) { if (IS_ERR(other)) {
err = PTR_ERR(other); err = PTR_ERR(other);
goto out; goto out;
...@@ -1404,15 +1403,13 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1404,15 +1403,13 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
int addr_len, int flags) int addr_len, int flags)
{ {
struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
struct sock *sk = sock->sk; struct sock *sk = sock->sk, *newsk = NULL, *other = NULL;
struct net *net = sock_net(sk);
struct unix_sock *u = unix_sk(sk), *newu, *otheru; struct unix_sock *u = unix_sk(sk), *newu, *otheru;
struct sock *newsk = NULL; struct net *net = sock_net(sk);
struct sock *other = NULL;
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
int st;
int err;
long timeo; long timeo;
int err;
int st;
err = unix_validate_addr(sunaddr, addr_len); err = unix_validate_addr(sunaddr, addr_len);
if (err) if (err)
...@@ -1432,7 +1429,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -1432,7 +1429,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
*/ */
/* create new sock for complete connection */ /* create new sock for complete connection */
newsk = unix_create1(sock_net(sk), NULL, 0, sock->type); newsk = unix_create1(net, NULL, 0, sock->type);
if (IS_ERR(newsk)) { if (IS_ERR(newsk)) {
err = PTR_ERR(newsk); err = PTR_ERR(newsk);
newsk = NULL; newsk = NULL;
...@@ -1840,17 +1837,15 @@ static void scm_stat_del(struct sock *sk, struct sk_buff *skb) ...@@ -1840,17 +1837,15 @@ static void scm_stat_del(struct sock *sk, struct sk_buff *skb)
static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg, static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
size_t len) size_t len)
{ {
struct sock *sk = sock->sk;
struct net *net = sock_net(sk);
struct unix_sock *u = unix_sk(sk);
DECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, msg->msg_name); DECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, msg->msg_name);
struct sock *other = NULL; struct sock *sk = sock->sk, *other = NULL;
int err; struct unix_sock *u = unix_sk(sk);
struct sk_buff *skb;
long timeo;
struct scm_cookie scm; struct scm_cookie scm;
struct sk_buff *skb;
int data_len = 0; int data_len = 0;
int sk_locked; int sk_locked;
long timeo;
int err;
wait_for_unix_gc(); wait_for_unix_gc();
err = scm_send(sock, msg, &scm, false); err = scm_send(sock, msg, &scm, false);
...@@ -1917,7 +1912,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -1917,7 +1912,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
if (sunaddr == NULL) if (sunaddr == NULL)
goto out_free; goto out_free;
other = unix_find_other(net, sunaddr, msg->msg_namelen, other = unix_find_other(sock_net(sk), sunaddr, msg->msg_namelen,
sk->sk_type); sk->sk_type);
if (IS_ERR(other)) { if (IS_ERR(other)) {
err = PTR_ERR(other); err = PTR_ERR(other);
......
...@@ -308,7 +308,6 @@ static int unix_diag_get_exact(struct sk_buff *in_skb, ...@@ -308,7 +308,6 @@ static int unix_diag_get_exact(struct sk_buff *in_skb,
static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
{ {
int hdrlen = sizeof(struct unix_diag_req); int hdrlen = sizeof(struct unix_diag_req);
struct net *net = sock_net(skb->sk);
if (nlmsg_len(h) < hdrlen) if (nlmsg_len(h) < hdrlen)
return -EINVAL; return -EINVAL;
...@@ -317,7 +316,7 @@ static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) ...@@ -317,7 +316,7 @@ static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
struct netlink_dump_control c = { struct netlink_dump_control c = {
.dump = unix_diag_dump, .dump = unix_diag_dump,
}; };
return netlink_dump_start(net->diag_nlsk, skb, h, &c); return netlink_dump_start(sock_net(skb->sk)->diag_nlsk, skb, h, &c);
} else } else
return unix_diag_get_exact(skb, h, nlmsg_data(h)); return unix_diag_get_exact(skb, h, nlmsg_data(h));
} }
......
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