aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2021-06-19 03:50:26 +0000
committerDavid S. Miller <davem@davemloft.net>2021-06-21 12:28:49 -0700
commit185ab886d3fb283e837283c343bf539c371e26cf (patch)
tree84588af36d7a0919e79a11985e79c45ef0e39459 /net/unix
parent43c9a8111680043d065025510a034336417084d1 (diff)
downloadlinux-185ab886d3fb283e837283c343bf539c371e26cf.tar.gz
af_unix: take address assignment/hash insertion into a new helper
Duplicated logics in all bind variants (autobind, bind-to-path, bind-to-abstract) gets taken into a common helper. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/unix')
-rw-r--r--net/unix/af_unix.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index c9dfec7b71e759..91447624a36473 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -262,6 +262,14 @@ static void __unix_insert_socket(struct hlist_head *list, struct sock *sk)
sk_add_node(sk, list);
}
+static void __unix_set_addr(struct sock *sk, struct unix_address *addr,
+ unsigned hash)
+{
+ __unix_remove_socket(sk);
+ smp_store_release(&unix_sk(sk)->addr, addr);
+ __unix_insert_socket(&unix_socket_table[hash], sk);
+}
+
static inline void unix_remove_socket(struct sock *sk)
{
spin_lock(&unix_table_lock);
@@ -913,9 +921,7 @@ retry:
}
addr->hash ^= sk->sk_type;
- __unix_remove_socket(sk);
- smp_store_release(&u->addr, addr);
- __unix_insert_socket(&unix_socket_table[addr->hash], sk);
+ __unix_set_addr(sk, addr, addr->hash);
spin_unlock(&unix_table_lock);
err = 0;
@@ -1018,7 +1024,6 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
int err;
unsigned int hash;
struct unix_address *addr;
- struct hlist_head *list;
struct path path = { };
err = -EINVAL;
@@ -1070,25 +1075,20 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
hash = d_backing_inode(path.dentry)->i_ino & (UNIX_HASH_SIZE - 1);
spin_lock(&unix_table_lock);
u->path = path;
- list = &unix_socket_table[hash];
} else {
spin_lock(&unix_table_lock);
err = -EADDRINUSE;
if (__unix_find_socket_byname(net, sunaddr, addr_len,
sk->sk_type, hash)) {
+ spin_unlock(&unix_table_lock);
unix_release_addr(addr);
- goto out_unlock;
+ goto out_up;
}
-
- list = &unix_socket_table[addr->hash];
+ hash = addr->hash;
}
err = 0;
- __unix_remove_socket(sk);
- smp_store_release(&u->addr, addr);
- __unix_insert_socket(list, sk);
-
-out_unlock:
+ __unix_set_addr(sk, addr, hash);
spin_unlock(&unix_table_lock);
out_up:
mutex_unlock(&u->bindlock);