Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1106841lqp; Fri, 22 Mar 2024 06:01:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUcH58HTyVHllOXqU+FAaC27rUK3SugdtOLt7VQ4zlEgB8fc5gu0lhTfsG13u6wpiv6lqKJec2GNpgEo+EElQZMh3eK8AIStcLexBIsIQ== X-Google-Smtp-Source: AGHT+IE2QDvXzu3CoQ3lTnMHHRU/eTCjKTxddPgdfQyKDkazsdAjMMyQOcocKuTMdNvN6igYvF3Q X-Received: by 2002:a17:902:7803:b0:1e0:4ce7:2e1e with SMTP id p3-20020a170902780300b001e04ce72e1emr2148575pll.29.1711112518961; Fri, 22 Mar 2024 06:01:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711112518; cv=pass; d=google.com; s=arc-20160816; b=tyjnuVkJOp5JWpYsgUu/eYV2cifLFgHqQVCsXqu/sTvZN3wA/1Q3qTF0qF5PpBE7lr Vr+3lp4MT+BMaw53Okdlhq99qm2Tj2f55gyecQNDAuXKnkJ6mHymYTfLy8qztmAf2A8P 9XhnMpXwVqDCHjUFEPV+qaz5XTK9YdTq2w05M/SxsdZ5fSprPQBq93AC6poWSSHOB8OO N23m2cVNufGvgzrM224egruOR10FsIPfv2tUpZhGLHosvi3fjRL/Yj0t/rJkaagazeKl U+ZSNqCSEKV9+AVQbMunPc5+SFCfLuAuWdP5XMgWU2rK710FzAwN+mHiOIYob6ezfy9I nBNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:in-reply-to:from :content-language:subject:references:cc:to:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=j5W+zIrNrwXHwy8i6ouAXhosP3kZXQBL5lb5KfWqjAo=; fh=RnSQuWhPW40UlUOFf8O2tnY7tc96FegXx4I07pEUWBw=; b=ITrq6bLLRA5UrvbRRiEkUfbBBMi6Djtgq3djm8/RsTgbmyNCbTePJLvnl//O1cMV7S tajLuM4CAHaKIJl0NnRCGQGgegw7BKV/rux+39z+b47GO2jYVt2AZeLUZWdSXQhz4LiK 8u3VMaDqHllF2kPupRrbIHtmvzUT565PbNms2+y+aCyUsepn0cJhuA/mw2BK2LoBYc5Y vBQyGD4typphPjW71inrGl0nCvDIwSsPsx4bs+gITaqhpn1BBQvbEeXX2TtZejY2ZPy0 7LCTRpMstZaEB5wCaRI/TTvPccwrVgm6SWOZrcdsSPXv9lQmBN5RUdwhPQZi5UclWXaR vC/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=GmDq6eJD; arc=pass (i=1 spf=pass spfdomain=web.de dkim=pass dkdomain=web.de dmarc=pass fromdomain=web.de); spf=pass (google.com: domain of linux-kernel+bounces-111448-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111448-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j13-20020a170903028d00b001dd8b2a3841si1962278plr.20.2024.03.22.06.01.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 06:01:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111448-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=GmDq6eJD; arc=pass (i=1 spf=pass spfdomain=web.de dkim=pass dkdomain=web.de dmarc=pass fromdomain=web.de); spf=pass (google.com: domain of linux-kernel+bounces-111448-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111448-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9002B282C50 for ; Fri, 22 Mar 2024 13:01:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AE4C45033; Fri, 22 Mar 2024 13:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="GmDq6eJD" Received: from mout.web.de (mout.web.de [212.227.15.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68BE645C0B; Fri, 22 Mar 2024 13:01:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711112500; cv=none; b=S08zRE7F6/Tb3fV5YZxxWpufmpgbDLpu4fHasKQyRZXkhuNgdUYGdpJIbY/x3DnLQc+6c/4TXkBLSpcm/HDmyiYWvjk/QkoWWCqcRxYT+heLkjq5wu3wNeCPo0MLMfUxX3O5G5zshDYch10twaxkDGGlbkNiscCtnY5HByB0HUk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711112500; c=relaxed/simple; bh=57Gnr1GDblaUtJoGzA33y6XntCYgqswvqSuwFA+G2xk=; h=Message-ID:Date:MIME-Version:To:Cc:References:Subject:From: In-Reply-To:Content-Type; b=Znt/q8EBx93x2EBI4V6DW4BMfgtBgvgDZ83hxttve0Huyn7DMHFYmvQul1zLcEZCCfFN8sXA4px0dp0lpw/eRvvKxnhvrgfc5k+qTx4RB6NPnpvaJNFpAtTa0LmEw56Vn5ireWofUOyjD87P7uCY4DHfb0dhTfkCUS0SwhUA4Vc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b=GmDq6eJD; arc=none smtp.client-ip=212.227.15.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1711112449; x=1711717249; i=markus.elfring@web.de; bh=j5W+zIrNrwXHwy8i6ouAXhosP3kZXQBL5lb5KfWqjAo=; h=X-UI-Sender-Class:Date:To:Cc:References:Subject:From: In-Reply-To; b=GmDq6eJDYgPPVb3quJwNngmgZIfK/mGylkG8DG1tBwkw+EOXza0QNOpkNTdHHw6q m2NrpRltTR/uuy4AT30Z3Zxy/8TtUwRwrNDkw7jUOGABVmzFe5YUj9/CbIvTCKyEm UbFWmOzF8t1sBIKMzWbsemMVu/xeKmHK35wlOSQ/3ktdfrTTNOgYXkiFnR3TtJSOI veliHEpzy4pXcnUhWlWPLRdxl+hnGbzrN9MEKhaLo1OmPNibdQLvX4yTLgDLwyzL+ freHk7CPcsYWKtrJPdpJjYrcZuMTfp2hHHh6zV9bf2H6376kQ0ADmRgtsrHosvuQp RwUIAHpaWm3asve6Ag== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.90.95]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MgRMB-1r6vNe1ovH-00ht8U; Fri, 22 Mar 2024 14:00:49 +0100 Message-ID: <8a1adff2-eb83-4dec-b8d0-1e523245de65@web.de> Date: Fri, 22 Mar 2024 14:00:42 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Dan Williams , Peter Zijlstra , Linus Torvalds , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kernel-janitors@vger.kernel.org Cc: Bjorn Helgaas , Greg Kroah-Hartman , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , Ira Weiny , Jesse Brandeburg , Jonathan Cameron , Julia Lawall , Lukas Wunner References: <171097196970.1011049.9726486429680041876.stgit@dwillia2-xfh.jf.intel.com> Subject: Re: [PATCH] cleanup: Add usage and style documentation Content-Language: en-GB From: Markus Elfring In-Reply-To: <171097196970.1011049.9726486429680041876.stgit@dwillia2-xfh.jf.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:UkSGC+4qo1n4XxoQDl15NnuOy58e3sPzB2i6UlqqDfSfdW9U9JQ 35gaoqp9m504/U5DfPHcqvKGeGm3kKpN378SPB3hEpNClCey/Yrbp1tFLLlJH3hMWbSufs3 ayuqzVHb0ioFxaqpyaaPMkJvuT7nZwJiYsRptUuE3FAmNDk8oRMghoIKKQSVXVGn0gDMGFH EJQ8MfXNN+4Q01lcJzLpQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:sDd5Oswr9wg=;oUpHLGsbXWg5ca5bC8NBGfysCrf DFv6hUPq8S4H/XwQpwPiQuK4HLa3C2XsqohEPgF8DqzZ2fDNQxfq5ZjtnTiRXOh+cIfSx0si5 I8p6NBAwC4kK18ez+vuj4QBiYZaedbKGinfljFLez8lz3PFDPoXvsJZ9FhWQUIY8x0KLDejZj 9SYVMpL7Hy2KSi85kGlwTXLj+OwNqHVdoBcZHVwXjiXUQLCFI9WqvY3zmPxKgYC3x1ql/1DeO 6iXHJ4zA7rzyBFgnZwFhA+sloNmWRsp7UQr5yT9HUFot1v3W//MS9grpfZoKs17jL7RM+7mqq VTJczbJTQY5/TS/miewAlPcLmi2qur+NZtXsdGMrOLgkpNuuwpVW5CylSlyQHwxHAl5OQSC0n hE/yVcRxZ+iIH1RMl6m9TNwEBvd1uvg4XvMbDaxPCLLbSQjp62otI96yLupwQNyHkvyOFlH6m 0kCUa+/bWDP8a8C72EV5qelNJEE3zux7FKyL6bWbZVjo6zs8T3HP0h9fmKjtnBSms3Jp6Lpui QmlqSE+Rae1sJUDalnx1KDcXNGI+N1D/aGvmytshJ1PgS4VRXj/hwjyrINOLgkGHuD7LuSscy jDoL363DGW2A1q5YWiEPzqKg0W7zBMepvkloBNElY5oIHN/GZNqfAVf5dhTyXqhWtbLLpbnHc 4f98L+PSD4h17gPOZusT1LB3gQCsD+MYLkKzIOfkNOTMpkpqoIccy7Xu8ao+FYHduF5742Ut/ roZZ91Y7fK8Bk2rKmukct+SBsyqR+6lB8+CB5nRb7ybqmJXj0S33GNNL8NMNtwh15WRT74dZ9 ak5aJWDVHTUL0WWtPbmSRaM3uFSuKvoFJUegBWNPntwQk= =E2=80=A6 > +++ b/include/linux/cleanup.h > @@ -4,6 +4,118 @@ > > #include > > +/** > + * DOC: scope-based cleanup helpers > + * > + * The "goto error" pattern is notorious for introducing =E2=80=A6 Will any other label become more helpful for this description approach? > + * this tedium and can aid in maintaining FILO (first in last out) =E2=AC=86 Would an other word be more appropriate here? > + * contraindicates a pattern like the following: I would prefer an other wording approach. > + * struct pci_dev *dev __free(pci_dev_put) =3D NULL; Programmers got used to null pointer initialisations. > + * In this case @dev is declared in x-mas tree style in a preamble > + * declaration block. That is problematic because it destroys the > + * compiler's ability to infer proper unwind order. Can capabilities be clarified better for the applied compilers? > If other cleanup > + * helpers appeared in such a function that depended on @dev being live > + * to complete their unwind then using the "struct obj_type *obj > + * __free(...) =3D NULL" style is an anti-pattern that potentially caus= es > + * a use-after-free bug. I suggest to reconsider such a development concern in more detail. > + * struct pci_dev *dev __free(pci_dev_put) =3D > + * pci_get_slot(parent, PCI_DEVFN(0, 0)); > + * > + * ...which implies that declaring variables in mid-function scope is > + * not only allowed, but expected. * Is there a need to separate the ellipsis from the subsequent word by a space character? * You propose a variable definition without specifying extra curly bracket= s (for another compound statement / code block). This can work only if an appropriate pointer is returned by the called f= unction. * The involved identifiers can occasionally get longer. Further code layout challenges would need corresponding clarifications. How will the handling of line length concerns evolve? * I suggest to take another look also at the transformation pattern =E2=80=9CReduce Scope of Variable=E2=80=9D. https://refactoring.com/catalog/reduceScopeOfVariable.html > + * Conversions of existing code to use cleanup helpers should convert > + * all resources so that no "goto" unwind statements remain. If not all > + * resources are amenable to cleanup then additional refactoring is > + * needed to build helper functions, or the function is simply not a > + * good candidate for conversion. * How do you think about to specify any more resource cleanup functions for growing usage of =E2=80=9Csmart pointers=E2=80=9D? * Would you like to extend the specification of function pairs for improved applications of guard variants? Regards, Markus