From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Peter Zijlstra <peterz@infradead.org>, linux-kernel@vger.kernel.org
Cc: Kevin Tian <kevin.tian@intel.com>,
Dmitry Ilvokhin <d@ilvokhin.com>,
Christian Brauner <brauner@kernel.org>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>
Subject: [PATCH v2] cleanup: allow scoped_guard() together with goto
Date: Wed, 2 Dec 2026 14:44:07 +0100 [thread overview]
Message-ID: <20261202134522.23563-1-przemyslaw.kitszel@intel.com> (raw)
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
reply other threads:[~2026-12-02 13:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202134522.23563-1-przemyslaw.kitszel@intel.com \
--to=przemyslaw.kitszel@intel.com \
--cc=brauner@kernel.org \
--cc=d@ilvokhin.com \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®