diff mbox series

[1/8] af_unix: take address assignment/hash insertion into a new helper

Message ID 20210619035033.2347136-1-viro@zeniv.linux.org.uk (mailing list archive)
State Accepted
Commit 185ab886d3fb283e837283c343bf539c371e26cf
Delegated to: Netdev Maintainers
Headers show
Series [1/8] af_unix: take address assignment/hash insertion into a new helper | expand

Checks

Context Check Description
netdev/cover_letter warning Series does not have a cover letter
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 7 maintainers not CCed: jingxiangfeng@huawei.com orcohen2006@gmail.com jamorris@linux.microsoft.com gushengxian@yulong.com kuba@kernel.org christian.brauner@ubuntu.com edumazet@google.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 4 this patch: 4
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: Prefer 'unsigned int' to bare use of 'unsigned' WARNING: memory barrier without comment
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/header_inline success Link

Commit Message

Al Viro June 19, 2021, 3:50 a.m. UTC
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>
---
 net/unix/af_unix.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org June 21, 2021, 7:30 p.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Sat, 19 Jun 2021 03:50:26 +0000 you wrote:
> 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>
> ---
>  net/unix/af_unix.c | 26 +++++++++++++-------------
>  1 file changed, 13 insertions(+), 13 deletions(-)

Here is the summary with links:
  - [1/8] af_unix: take address assignment/hash insertion into a new helper
    https://git.kernel.org/netdev/net-next/c/185ab886d3fb
  - [2/8] unix_bind(): allocate addr earlier
    https://git.kernel.org/netdev/net-next/c/c34d4582518f
  - [3/8] unix_bind(): separate BSD and abstract cases
    https://git.kernel.org/netdev/net-next/c/aee515170576
  - [4/8] unix_bind(): take BSD and abstract address cases into new helpers
    https://git.kernel.org/netdev/net-next/c/fa42d910a38e
  - [5/8] fold unix_mknod() into unix_bind_bsd()
    https://git.kernel.org/netdev/net-next/c/71e6be6f7d2b
  - [6/8] unix_bind_bsd(): move done_path_create() call after dealing with ->bindlock
    https://git.kernel.org/netdev/net-next/c/56c1731b280d
  - [7/8] unix_bind_bsd(): unlink if we fail after successful mknod
    https://git.kernel.org/netdev/net-next/c/c0c3b8d380a8
  - [8/8] __unix_find_socket_byname(): don't pass hash and type separately
    https://git.kernel.org/netdev/net-next/c/be752283a2a2

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 4d4f24cbd86b..464473a78b05 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);
@@ -912,9 +920,7 @@  static int unix_autobind(struct socket *sock)
 	}
 	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;
 
@@ -1017,7 +1023,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;
@@ -1069,25 +1074,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);