Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6066767rdb; Mon, 1 Jan 2024 07:29:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IENWDb7aXQtq+H15LDBS33O4tkqDnb19gmhk85qeMON8o6o4TrBU0kefEIy+MtDcZF8BmiC X-Received: by 2002:a50:d48c:0:b0:554:e091:a517 with SMTP id s12-20020a50d48c000000b00554e091a517mr5055769edi.18.1704122978770; Mon, 01 Jan 2024 07:29:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704122978; cv=none; d=google.com; s=arc-20160816; b=05DzI51G2jYANxvmwrXK6jQE43PQSNEQR7KhScj0PeBeeRCHnc3nnX9qht6+gLcORg PadnlmtHWCu+WEjQS4JzYREG9IKVJK21w1MqkiZwP1YA7YXk2FMQ18so/PzA3Y5IjZV5 lh78psVVHVKUFWtts7eCPYZ3wmUteE9qonXJwEJMxv/ITHMEsnlt7qXfm9PSKXTwM/Zd Rr/5qqTQ2N1N2bUJ9A00A2YKgKVjpFjt2O8LfKUXvnZWdGpOk/x3kXO1hol6hc8IkHQ5 aemWmCbe3H50mKqPYTBQD9LEgv6m/UR65iGBQI8Oc5AdeE2sQl/k0YTNtEHp4TgcdXV9 HdPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:references:in-reply-to :message-id:cc:to:from:date:dkim-signature; bh=dOai/QjEk7Tqo03+RAmdQPXZT0jZzm9Xucc4X/XwTic=; fh=CYatQ6ln+eVCWgwfXhyQWkg5cqBr5pc7qcu1NE3mLGI=; b=YYSrsWrE3Z0pFBH18ZGvtjqMscav6MNUPWqZ6ykqXVez7fGZb61J+IxhZs+EQPRSCz ZOCyxIVrr11c0f0hNCde7yuHiC1yc0BGGEeM6svGGk6+K4mAdNYCSyRTC5QrTn9oCFE7 1GHxpUixPZAYWpCLxsCY3SJECyrW3sZf0ZwXn8olxXoVtwBgSO4E7fO3swmhJihSA8fe 7Au5tqROdwvTt1AOWkoBQPJ3rHL3osUH3jQ0oy5oTNwzUIl1+GaSfPu0Ps796S/Eptbx hCXk3AP5HrDRCAnRlndiKcQyFwJxrfk573l8eelYQCmDCItc+JRypQv9OrtPvkXa2MXe bCcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=S0MHm4CD; spf=pass (google.com: domain of linux-kernel+bounces-13884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13884-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f29-20020a50a6dd000000b005543ec7a80fsi9505499edc.159.2024.01.01.07.29.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jan 2024 07:29:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=S0MHm4CD; spf=pass (google.com: domain of linux-kernel+bounces-13884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13884-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 84D601F2161D for ; Mon, 1 Jan 2024 15:29:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70BA26AC0; Mon, 1 Jan 2024 15:29:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S0MHm4CD" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DFD76108; Mon, 1 Jan 2024 15:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-78160ce40ceso278473585a.1; Mon, 01 Jan 2024 07:29:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704122962; x=1704727762; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=dOai/QjEk7Tqo03+RAmdQPXZT0jZzm9Xucc4X/XwTic=; b=S0MHm4CD52KaEEjeuvYmjsrwjjdRyG+EID0hl8vFwr68Ctf5/jH3OMdnakoxzhVAx2 Q/cbQvViQl7DoeFa6zcSWOUYXNUcNPMWn4As+Y8mgTEXN2sywENrZVcZdv9la79IyqdQ vYSLdxtmBqJUqRz/FrLhjat+MYD/gmGK6Xr1OtXtXd3zHjdpzUeuFAumW9Me/sDk054S t0FVJA+K72n3fcwT47MwxmlmRXgzVJhIbDF7JxNOWIu05WUKjjLVL4Fjb530nIU4FyBY IzolDWyvUY5cZAp8sR624KW89uEz3rfQyipilvZHJkK+SY08/ncVcD40htuMx6uHqVv+ O5mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704122962; x=1704727762; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=dOai/QjEk7Tqo03+RAmdQPXZT0jZzm9Xucc4X/XwTic=; b=Qfhfs1EuI/uXAJCuM6tlm82QHMioxS/zCjOIv9a3hPUIMvfBFe7BrwLtZP1g2KRsuI KqYeIi/j0TSFZQHBZqzrlTJyKkECYnIQyN2CzmBYB83MG5aHqLwFw4KSN3km/Cu0g8xr svMmFZD13t4NV7qTXgH6jPa3z+8dCqrk3BpP943zYm+7G+B0fFK3QbP6xxF8P8Ga0MPo XX9w3aIr0mhOHWXRjB5V1afQD7pJ40evrsBTSuovPbXlBKDR32yeMNsxoa37QYJEA2/5 kCpT6e7ZY3VDdOh4RR8TFn3TVoGsE/qExoMSM9zqjPtX82mxkRyNwDKBTz3WzPv7Wfmn pDdg== X-Gm-Message-State: AOJu0YwTBoIpDPgEro7VdUPmwgNim8JcHHVrkm6z+Wk9QeF1NY8X2AWF tvPYMLbrCtrwm8c4oGADjGs= X-Received: by 2002:a05:620a:111c:b0:77d:85d9:c655 with SMTP id o28-20020a05620a111c00b0077d85d9c655mr15082676qkk.14.1704122962028; Mon, 01 Jan 2024 07:29:22 -0800 (PST) Received: from localhost (48.230.85.34.bc.googleusercontent.com. [34.85.230.48]) by smtp.gmail.com with ESMTPSA id bq14-20020a05620a468e00b00781d60d3597sm95985qkb.120.2024.01.01.07.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jan 2024 07:29:21 -0800 (PST) Date: Mon, 01 Jan 2024 10:29:21 -0500 From: Willem de Bruijn To: Markus Elfring , Willem de Bruijn , netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Stephen Hemminger Cc: LKML Message-ID: <6592da5178589_238b0d2943a@willemb.c.googlers.com.notmuch> In-Reply-To: References: <828bb442-29d0-4bb8-b90d-f200bdd4faf6@web.de> <6591e0fcb089f_21410c2946c@willemb.c.googlers.com.notmuch> Subject: Re: packet: Improve exception handling in fanout_add() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Markus Elfring wrote: > > It is fine to call kfree with a possible NULL pointer: > =E2=80=A6 > > * If @object is NULL, no operation is performed. > > */ > > void kfree(const void *object) > = > Such a function call triggers an input parameter validation > with a corresponding immediate return, doesn't it? > Do you find such data processing really helpful for the desired error/e= xception handling? It's not just personal preference. It is an established pattern to avoid extra NULL tests around kfree. A quick git log to show a few recent examples of patches that expressly remove such branches, e.g., commit d0110443cf4a ("amd/pds_core: core: No need for Null pointer check = before kfree") commit efd9d065de67 ("drm/radeon: Remove unnecessary NULL test before kfr= ee in 'radeon_connector_free_edid'") An interesting older thread on the topic: https://linux-kernel.vger.kernel.narkive.com/KVjlDsTo/kfree-null My summary, the many branches scattered throughout the kernel likely are more expensive than the occasional save from seeing the rare NULL pointer.