* [PATCH v2] cleanup: allow scoped_guard() together with goto
@ 2026-12-02 13:44 Przemek Kitszel
0 siblings, 0 replies; only message in thread
From: Przemek Kitszel @ 2026-12-02 13:44 UTC (permalink / raw)
To: Peter Zijlstra, linux-kernel
Cc: Kevin Tian, Dmitry Ilvokhin, Christian Brauner, Przemek Kitszel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-02 13:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 13:44 [PATCH v2] cleanup: allow scoped_guard() together with goto Przemek Kitszel
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®