Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp548047pxb; Sat, 20 Feb 2021 12:34:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJU2e03yv7BPmLbQqZWtSm8Cn1yoDZzVWCGk/rXxZDHP/ewcRkyogPO+lUyAkV3kPNoIml X-Received: by 2002:a17:906:2e96:: with SMTP id o22mr14455068eji.190.1613853270551; Sat, 20 Feb 2021 12:34:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613853270; cv=none; d=google.com; s=arc-20160816; b=YoQhanCfpa1PiYNu9TB9Cwq0bPmd0Bxf9zVRyXXNZnHb/DzbW6UgCp63uXylyF+Z0f 0J/O6frloy0AjR3Qr/yI2CNJCT8LWb16dgJ32mWpM2DlyEZ654UNfSjvuMA8p+f4iuke q16JVSOrP0m+bNkEeAq55K+/SD6YLjEJT6gFwZ6OXvbkV9R6Z0BLteyvhMxVOcYyNaMx VD1dnHno9OVL3ApETzyB/OlX/9unO/cX4rEobq4oBy2HQu2T+kuaRh0/G1rsW4yjXXNH K18nDRJXOWWkPHI0xkqRwDrc3AbeetLq3iuiXmzxVi4u0jGoA7Zs1yO29GAGo3t7tYD/ nd/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2lPQnSKSrFdOexh+uYv9Tnzq5Tv9KMipC5F/AsHVpd0=; b=VUhs4R+0EPeiWsu1/3RzoQS+ZNIWpfT8tMlOh2deW/k9gfRJurQH+JVnbQeXPPwTKp Tx8xXc+uD62PvmgD79Wcy5PLaKDyvB+nazGx6LL/eyz9crN2cWm1P2MnaXAvgQMo2Bqe DRDDYOwTWIItSlWCGUuJ9Or/tk2AFhcMqGax8kbpShW4m85m+lL2pRQIUMB5I1c55CMo +bejomJBcEinhm4oliJVdXc9VPGT29oXaRdWLbMypn5DzNsahA9amg68g6WlwOhBt42Q CeU3Uwfe8DuaFMdZJ+aA+eWfQUWZZEmC77pi+1nTrd0nNgCA4C88j94ZOdsKm4Q1Z1ku EulQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qGqVwlcq; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hc6si3914044ejc.554.2021.02.20.12.34.07; Sat, 20 Feb 2021 12:34:30 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qGqVwlcq; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbhBTUcn (ORCPT + 99 others); Sat, 20 Feb 2021 15:32:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbhBTUcm (ORCPT ); Sat, 20 Feb 2021 15:32:42 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC77BC061574; Sat, 20 Feb 2021 12:32:01 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id c11so4129664pfp.10; Sat, 20 Feb 2021 12:32:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2lPQnSKSrFdOexh+uYv9Tnzq5Tv9KMipC5F/AsHVpd0=; b=qGqVwlcqnBfhRqAi3KkxtsW6vT/XdXVJXXILMQXUJLz0eTuZeof3OAdrWRPT44B6LO H+NirSV71/8p+EDkwXwmzs/tAx9JZSLAF734gMyiiCkGQx7Dr8wXrpTh58+hyVJtM4fD DKilUr9kKeXlOUctFAZ5x+LnVQY51434i+2A5wwqqm6EUGRKa4a2YZM1Uk3FhSVc/RnF E4MnZKfbW+GyRckbrJO72ZDYWHeZLbCyrmxKXFO/dFE673Kw3faqsuq3gKb47dvvRx3t E45eQ2LRZk7jM+OLMebxBiWhG5ALLii6x8IRCOVKsZWj5WySvvVtDLm4FoGxrpnMFwbM RMPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2lPQnSKSrFdOexh+uYv9Tnzq5Tv9KMipC5F/AsHVpd0=; b=P1bT5ewgCHuqAk/rqtR5T5DEQaucjMIu7Y15uD3HLFD2nKpp9WrJbM5FcI0C0ZT2oX 27BGDRm2SuH0dx+b7sXEOMhS/pxOUlo+RtbBevlkabJauHwBkr1z6hJZRj28BrKI9BiM bPqUKdzx7NX5oA5hgBcaNujUz0t+K04BT6TJivizCPCyPx09W9qwdfv4Rk6qtRz0cTUb eMj8aqrptjaVbpV46xGcy87gv5ipnEOUeN4gDu8RivOehuN7Ca35a8yBzVrytVyXlA+y KWc11MZbB37i10WI1dxX0H8MLoUpHTWl7+8UByUg0r6VYaw84d4ER8NI09b6F+YNPVui hwHQ== X-Gm-Message-State: AOAM530MAsVB8Gxi+IGKzPMBlNtLZytLj/F3ZeaG1CqW2+v2P0ZIdAUG 2JnlEaXxMqm2IMhyUjKZoPxKfJHIcI8JppLn5gU= X-Received: by 2002:a63:eb14:: with SMTP id t20mr13572411pgh.336.1613853121265; Sat, 20 Feb 2021 12:32:01 -0800 (PST) MIME-Version: 1.0 References: <20210129082524.GA2282796@infradead.org> <20210129131855.GA2346744@infradead.org> In-Reply-To: From: Cong Wang Date: Sat, 20 Feb 2021 12:31:49 -0800 Message-ID: Subject: Re: [PATCH 1/8] af_unix: take address assignment/hash insertion into a new helper To: Al Viro Cc: Denis Kirjanov , Christoph Hellwig , LKML , Jakub Kicinski , linux-fsdevel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 20, 2021 at 11:32 AM Al Viro wrote: > > On Sat, Feb 20, 2021 at 11:12:33AM -0800, Cong Wang wrote: > > On Thu, Feb 18, 2021 at 8:22 PM Al Viro 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 > > > --- > > > 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); > > > > Please take the unlock out, it is clearly an anti-pattern. > > Why? "Insert into locked and unlock" is fairly common... Because it does not lock the lock, just compare: lock(); __unix_set_addr(); unlock(); to: lock(); __unix_set_addr(); Clearly the former is more readable and less error-prone. Even if you really want to do unlock, pick a name which explicitly says it, for example, __unix_set_addr_unlock(). Thanks.