Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7748816pxb; Thu, 18 Feb 2021 20:23:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNuLXsyJM5R/OYk7cNd2P/v9cEyNMQqWMWGIoyIaqj/4TV4GXr9i8NaKFyvmCjxHhbyHKy X-Received: by 2002:a17:906:7fc4:: with SMTP id r4mr6930158ejs.81.1613708590906; Thu, 18 Feb 2021 20:23:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613708590; cv=none; d=google.com; s=arc-20160816; b=Krm5ZHOTFe8sL3pDEizvJStRovRsmOxlWOy+aWGq+/JjCY5IVh152g6SNMzFUghZ3V 9R4sxwxLEkrZnBABFKmD7Z9R1G2YaN2Vu2su0r+IIKbu63nCTUjRyhgb945PKkwgVIH0 sIXKOjYNAC4xfF4+JIDj/0zp1WFIjMhP6NDGj/SQx35eIu+XnVoV4/vOL7dbYmcIhYZr oCA+Rrek/hBLxpAfwJIz/HzT6K+/MavNDyn6uyf3bPot5L1q8rQYYX7W4Rxhdz6HsJci +6x/0kMXz7xaJAAQs7owx2I760pIUnTDk2+PRrIiK3HdyNqZvTsi52LtWsL/wo6tgki1 S2yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=YNAbaaougQKe+hJDRssnfz2nmMvkynIZuPBkIip+1eM=; b=s+1IORDSLAPoG92pczsndor+A61pPTh6ZUO5tyLQYFBJwCf8lI5fdu/TqCIiLZgT3h TjS89Bx6D2t7q4LNHZYP4u65X14XS1cz8mzgzup7uLIB5bwFxC6JqprwGuUaomcgaHpd enFsHJ5pAlL8uTW2j1fNtA7kTGT+6ffUVuUacN7fSD1iHOAaVIhAYhNBYi6NUF4lLqB3 XcG5j3AWGd2QmL/eC1wgTNL1hB4zmseS3OH9PpM6Qx8uwLwKCcqhqM09Z7/+Er20Yyb0 GLJZu8pBtxTp/OzpHoRqKOvX+FYUNz5PDRtLquLmdXVSPZ8IQaxW4sC5uyqSS8IYJT6G cnQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si5586539edd.161.2021.02.18.20.22.48; Thu, 18 Feb 2021 20:23:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbhBSEUm (ORCPT + 99 others); Thu, 18 Feb 2021 23:20:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbhBSEUk (ORCPT ); Thu, 18 Feb 2021 23:20:40 -0500 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2665BC061788; Thu, 18 Feb 2021 20:20:00 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lCxGj-00FgV2-IR; Fri, 19 Feb 2021 04:19:53 +0000 Date: Fri, 19 Feb 2021 04:19:53 +0000 From: Al Viro To: Denis Kirjanov Cc: Christoph Hellwig , linux-kernel@vger.kernel.org, Jakub Kicinski , linux-fsdevel@vger.kernel.org Subject: [PATCH 1/8] af_unix: take address assignment/hash insertion into a new helper Message-ID: References: <20210125154937.26479-1-kda@linux-powerpc.org> <20210127175742.GA1744861@infradead.org> <20210129082524.GA2282796@infradead.org> <20210129131855.GA2346744@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Duplicated logics in all bind variants (autobind, bind-to-path, bind-to-abstract) gets taken into a common helper. Signed-off-by: Al Viro --- net/unix/af_unix.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 41c3303c3357..179b4fe837e6 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -262,6 +262,16 @@ 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) + __releases(&unix_table_lock) +{ + __unix_remove_socket(sk); + smp_store_release(&unix_sk(sk)->addr, addr); + __unix_insert_socket(&unix_socket_table[hash], sk); + spin_unlock(&unix_table_lock); +} + static inline void unix_remove_socket(struct sock *sk) { spin_lock(&unix_table_lock); @@ -912,10 +922,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); - spin_unlock(&unix_table_lock); + __unix_set_addr(sk, addr, addr->hash); err = 0; out: mutex_unlock(&u->bindlock); @@ -1016,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; @@ -1068,26 +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; } + __unix_set_addr(sk, addr, hash); err = 0; - __unix_remove_socket(sk); - smp_store_release(&u->addr, addr); - __unix_insert_socket(list, sk); - -out_unlock: - spin_unlock(&unix_table_lock); out_up: mutex_unlock(&u->bindlock); out_put: -- 2.11.0