From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796219132; b=QA8Nb4o0c7D9VpQJloijfqZuYhiTttOs8JPWZVyL9bpzvFS/Gs2ZtXsphx0HFSvHgoz8 XSjhfpvmFQSETpTp+OOfcCc5Iy94itWm04HEfK16c9TXaNawhptVVQBbkEhZL3L2lh3RL WClcLT7wJ6pSc6YPfJ5u5McLGc+W5Ms07jYcnhSFj69mSVl8PQqtLVP/ky/giaEQr2gYR DNH+mF8DY/bhlR749HcOTBQuLsuaJyHz06xfBSAO18q3lK65zOikVWcnibNsEEXvlbn1P Eqs+tmGYwk5dpjfJ2lIFMLSdf8nL7X8B+ueciPEHjptl4osK905BKBIPc136yf3MFCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796219132; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=An4Lum8b5n+Ci/5ukitRRcPyRVSddKZYoAHlAXNkjFA=; b=umWh7/wKX+VAdv1X02ytnjPJr9hYDFzpET9KAD1iVa+B+/z4PSjTk3mnUFfeFtixkQ3q Zmipshyge3dDYSk4oPrKpv9F/MJAVrbO5/tP7fsMTTM1yXf59uxMm11C0Hz8ytm5UYqux 2zxNQy1bWzeWSHbwB0EwOegPS8vMICZz7RtKsLzc0ObqgeOKnkQM0NoCXrkYuEXYpryCi P8TW87NnuF/Mzej/O1NnVry0rMidOk9p4cDjzYmdACZC1Ln8kOS0G6F+asIo8Ljhg2uHo 2rAwAGg9pjTIIYKIitdaa1QlEkJDi97nuGYsb5SQTxO59TJwMuf32bIhxb7fcndUqPQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=DcYtEohb; arc=none smtp.remote-ip=192.198.163.9 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93E1B606A31A for ; Wed, 2 Dec 2026 13:45:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93E1B606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=DcYtEohb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796219132; x=1827755132; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=An4Lum8b5n+Ci/5ukitRRcPyRVSddKZYoAHlAXNkjFA=; b=DcYtEohbG34D2BIg8gpY3eCu2F8Fy4fx6NqvusR2VKdmaO844fEgMrgg fFUfh4LRJBKO8qio5cF4Pt85ZPJesAsqJUNGxXH0TmO3RQIYfMrY3nBAO p3G31telNNO79O9AvMdVWL5NdViV49gumhxGZk1vAJ805YrxwJNORdFlp rSMyi+Jys8aeIhhFINMYXRR2MKnGFHf7JlkpkYz2k7lpLxxM+vPuUlN2c B2ThlpIVZv0Eteoji0Iaz3ZVd4205YZeXN4zOb0y3Em8Lu8qFnyYsjPBb lcr+97HEB8Lr/dlXkzyUKSQGYBKQ1Iujg8VtSfnlsLvmuZQ4rwJ8VNobT Q==; X-CSE-ConnectionGUID: mygPyJGaStKTTGjkmfwFjw== X-CSE-MsgGUID: DSwRWD2aT8awwqHvq1cp+A== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5000831" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5000831" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 05:45:31 -0800 X-CSE-ConnectionGUID: H9UnniNIQ0+Xn/AIQE5twA== X-CSE-MsgGUID: uYOeFnBPSgCrhAQX1hy18Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13826604" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa006.fm.intel.com with ESMTP; 02 Dec 2026 05:45:29 -0800 Received: from pkitszel-desk.tendawifi.com (unknown [10.245.245.227]) by irvmail002.ir.intel.com (Postfix) with ESMTP id C85772FC61; Wed, 2 Dec 2026 13:45:27 +0000 (GMT) From: Przemek Kitszel To: Peter Zijlstra , linux-kernel@vger.kernel.org Cc: Kevin Tian , Dmitry Ilvokhin , Christian Brauner , Przemek Kitszel Subject: [PATCH v2] cleanup: allow scoped_guard() together with goto Date: Wed, 2 Dec 2026 14:44:07 +0100 Message-ID: <20261202134522.23563-1-przemyslaw.kitszel@intel.com> X-Mailer: git-send-email 2.51.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The guidance in cleanup.h is to never mix "goto" and cleanup helpers in one function. That is needed for __free(), guard() and ACQUIRE(): they live until the end of the enclosing scope, so a label placed after them, like an error path, ends up inside that scope. scoped_guard() is different, it has an explicit scope. A label after it is outside of the guard, and people do not "goto" into its body. Error paths that unwind other resources by "goto" are common, and the blanket rule makes them look wrong to readers and to automated reviewers, which flag them repeatedly. Allow scoped_guard() in functions that use "goto", and keep the rule against jumping into its body. --- v2: - relax the rule for scoped_guard() only, guard() and ACQUIRE() stay discouraged (Peter) v1: https://lore.kernel.org/all/20261125161205.65809-1-przemyslaw.kitszel@intel.com --- include/linux/cleanup.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index 1fb8058b897d..8d978e518871 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -151,6 +151,11 @@ * mixed in the same function. I.e. for a given routine, convert all * resources that need a "goto" cleanup to scope-based cleanup, or * convert none of them. + * + * The exception is scoped_guard(), as its scope is explicit and ends at + * the closing brace of its body, so a label placed after it is never + * inside of it. It can be used in a function that uses "goto", as long + * as no "goto" jumps into the body of the scoped_guard(). */ /* -- 2.51.1