Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1806753pxb; Mon, 22 Feb 2021 11:21:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzTmpzOIy4EsXWFB7EgOE3aPizPQ7Tx474AUnnbSLklrKT+FYQ03YvJ5/7Q7P/sMv7qWuyf X-Received: by 2002:aa7:ca08:: with SMTP id y8mr11037518eds.256.1614021666559; Mon, 22 Feb 2021 11:21:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614021666; cv=none; d=google.com; s=arc-20160816; b=mrnMwjLlvZY7KLG+VzppPEit9gO/XiIzWI92exX6LpWcX8D+Y3DKWUb6/765nIy8RG HMX+qocjM3dncwDPr9+MVhpcTgOOXNLsXIYihSHvvLl7qNQVf6M+oh+MAgYyWrjH4QlS F2B4zl12/t3TxPuOi+C4GhNfoiBRFuNcSgW+l0V97f6/S54QkQwutOK8hB/IGTGp7Qq1 mrKdBNyO5E6JsWKr2AK92VwgstllH+9vHffAJgn9+EcgtQPsB0Xx7cr2Hpfn9r9WG6RO BDH41cctdlvAxeAIJuS20FPouqaKHAQR2yJoSyJpKC17qy7BTZ1Vvqmf8VVgdMnP5qeV 6Wsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=r57lg4r2wCpKOsyb4fm2sLdXLoJpTIadP3t5s31NAvo=; b=iv+jjOhDIqmZMMAibbYR2LZxtWtTB/pO2Yvux0BhxCByfZ3qHMfJjQOcyAJ5BLXhYc tdSCobFrAXXn0rY1iomaZo/Wdw3b7C2rw+yuTcWwsDEA9qeWqCytYZQGANFTDPCWzDcZ RP72jdxQHOJtp4foY7PI67o+ThR4gphfIueAeCkwLLewNKqKdOdhYaCrIU8/ZA9QrxgN /R6O/6NsXIRu7i8I/ptXQHesbiQAudTdKZh20Td3lYtf9riF99eviHcncC6/Zz8HuYIN QfdrsD2MKcqJYMTkovvcZKoL9gZVgV4qVTJ43VEZV+5FiKy1ZBsUwtsqfUAprCd5pfGy jX9g== 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 u20si11146806ejz.339.2021.02.22.11.20.42; Mon, 22 Feb 2021 11:21:06 -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 S232955AbhBVTT7 (ORCPT + 99 others); Mon, 22 Feb 2021 14:19:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232806AbhBVTNG (ORCPT ); Mon, 22 Feb 2021 14:13:06 -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 C2F7AC06178C; Mon, 22 Feb 2021 11:12:25 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lEGd4-00HAzj-3X; Mon, 22 Feb 2021 19:12:22 +0000 From: Al Viro To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Jakub Kicinski , Denis Kirjanov , linux-fsdevel , Cong Wang Subject: [PATCH 1/8] af_unix: take address assignment/hash insertion into a new helper Date: Mon, 22 Feb 2021 19:12:15 +0000 Message-Id: <20210222191222.4093800-1-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 41c3303c3357..45a40cf7b6af 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; @@ -1016,7 +1022,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,25 +1073,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); -- 2.11.0