Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2617050pxt; Mon, 9 Aug 2021 05:06:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMD4t9y2WF7ccuel3dOFwQ2Q0S6cz0/3OPjLcvg5vSMntuXJsIK1X3iVCc0xjSqp2Ptqrk X-Received: by 2002:a05:6602:2e0e:: with SMTP id o14mr381044iow.161.1628510760494; Mon, 09 Aug 2021 05:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628510760; cv=none; d=google.com; s=arc-20160816; b=MtsT8CkaM0y6lCggM0+ZoltOCplGuPZVBzmQSCBWPYAPzXnYs7vKu+7eYkvPNKYJuH Alkz2QjWSdQ+x9pcQGQ7wRxR5LTiTsfCkNjbuo6hQSdUeN/P3c+lCCnKZUYNBijPjbx7 wTGceZynK0/u1kh+1tTe068W1fX2nvW/beHU5hoxcFo3zFPXFIcKugdKsNhsbTlE6W00 dnSOM4WrKneVHWFVAvHxqFSJJmZK/23RGKZlHb6c7zsa/lAbnAbxduQAjAUa4d3YMUEr 5Lo+HBciZZoOTxfEtlew5JwHb5LfQsnCqlvr0OqFT5VR0Kcy3+ZnxN0Bl4R0m3OhoF3b n71g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4GT8yoQK1nTQj81sD/hsoGEzfFPRlTkYKb34nQXn+O4=; b=l3o8BmX2SqNhA/9YxNy6xQHQERGp/yphPWoZsVv6PMwmRtOxl/rxoYknXkzAaxogb9 Sdcu7ckgU5ZieY4JlIYkGU8hRT33FgHTzO6CxP79HysfojOsp7EXvZkV4zrQOnwAoa0Y OGDao74L4TWfM48W/KKaytravIwR5ESlfSPYztau9GHZaQb3mmE9Oa3VEj81KPAYiyJf 1qu9fqcFxgoGNep67c459LuITjnShWyOibTzGYqHaGj/S6lVsE5FV+WZzlNKhAJY8ytr 7Zu1LrUnsJbiHRonjD6wRFJabF4fMN/GjH5N1qxnRMdGp2BGuFZOPkxcFDkC9ZXgwM9W WRCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c5csrOUU; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w21si8087898ior.60.2021.08.09.05.05.46; Mon, 09 Aug 2021 05:06:00 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=c5csrOUU; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233785AbhHIK22 (ORCPT + 99 others); Mon, 9 Aug 2021 06:28:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:58038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233720AbhHIK21 (ORCPT ); Mon, 9 Aug 2021 06:28:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 21AE76108C; Mon, 9 Aug 2021 10:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628504886; bh=1Rr9G2WTvyN2154ArfnkrxNB++dNyHRWTlM42K7U3LA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=c5csrOUUWBbIRXzbnhuusFcKO2ZeeMaQD8XIm2H8GWZBQ7BSxySLPLGqYwCZA024M apCWfvT5lSqwva4SO63w3ic1sydrdWQvtLxpHaZcWhYso2Wu/+XypiVbNth9xyieXg VdKbIwBeYelyv9/VMO0E0544HrzE7W/M80n4CqhHisqxMME40Io/EioTBiydXFdQxk J9zk2taAZoFk6xJivLRSzdFHYLafqRUg+X7VWiRO8ZgeYaUD30DAQiJngpsVvd8xsj JgAjZ95phOJE0B9Gbtim7NqfFU2Q+W1o8qcSJ6VhggVLY+IYwhUAXEx1br8UBeLD6c 75ci93sNK/ybA== Date: Mon, 9 Aug 2021 13:28:02 +0300 From: Leon Romanovsky To: Eric Dumazet Cc: yajun.deng@linux.dev, Jakub Kicinski , davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] net: sock: add the case if sk is NULL Message-ID: References: <20210806061136.54e6926e@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> <20210806063815.21541-1-yajun.deng@linux.dev> <489e6f1ce9f8de6fd8765d82e1e47827@linux.dev> <79e7c9a8-526c-ae9c-8273-d1d4d6170b69@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <79e7c9a8-526c-ae9c-8273-d1d4d6170b69@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 09, 2021 at 11:34:31AM +0200, Eric Dumazet wrote: > > > On 8/9/21 8:12 AM, yajun.deng@linux.dev wrote: > > August 6, 2021 9:11 PM, "Jakub Kicinski" wrote: > > > >> On Fri, 6 Aug 2021 14:38:15 +0800 Yajun Deng wrote: > >> > >>> Add the case if sk is NULL in sock_{put, hold}, > >>> The caller is free to use it. > >>> > >>> Signed-off-by: Yajun Deng > >> > >> The obvious complaint about this patch (and your previous netdev patch) > >> is that you're spraying branches everywhere in the code. Sure, it may > > > > Sorry for that, I'll be more normative in later submission. > >> be okay for free(), given how expensive of an operation that is but > >> is having refcounting functions accept NULL really the best practice? > >> > >> Can you give us examples in the kernel where that's the case? > > > > 0 include/net/neighbour.h neigh_clone() > > 1 include/linux/cgroup.h get_cgroup_ns() and put_cgroup_ns() (This is very similar to my submission) > > 2 include/linux/ipc_namespace.h get_ipc_ns() > > 3 include/linux/posix_acl.h posix_acl_dup() > > 4 include/linux/pid.h get_pid() > > 5 include/linux/user_namespace.h get_user_ns() > > > > These helpers might be called with NULL pointers by design. > > sock_put() and sock_hold() are never called with NULL. > > Same for put_page() and hundreds of other functions. > > By factorizing a conditional in the function, hoping to remove one in few callers, > we add more conditional branches (and increase code size) You can add into your list that such "if NULL" checks add false impression that NULL can be there and it is valid. Thanks >