From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Peter Zijlstra <peterz@infradead.org>, linux-kernel@vger.kernel.org
Cc: Dan Williams <dan.j.williams@intel.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Kevin Tian <kevin.tian@intel.com>,
Dmitry Ilvokhin <d@ilvokhin.com>,
Christian Brauner <brauner@kernel.org>,
Ira Weiny <ira.weiny@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>
Subject: [PATCH] cleanup: clarify scope-based resource management and goto guidance
Date: Wed, 25 Nov 2026 17:12:03 +0100 [thread overview]
Message-ID: <20261125161205.65809-1-przemyslaw.kitszel@intel.com> (raw)
Scope-based resource management helps manage resource lifetimes, but it
does not solve rollback of a failed operation. Such rollback is often
best handled with multiple goto-based unwind paths.
The current guidance can be read as discouraging any cleanup helper
alongside goto, including guards. Automated reviewers repeatedly flag
code that mixes the two, so clarify that the recommendation applies only
to __free().
Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
---
I develop mostly in the subsystem that bans __free(), which is also
most low-level of all the helpers - so I get that we could discourage
mixing __free() and goto. But for the rest it is counter productive.
---
include/linux/cleanup.h | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index 1e09aead4b08..3b852198e969 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -145,12 +145,10 @@
* statement and not group variable definitions at the top of the
* function when __free() is used.
*
- * Lastly, given that the benefit of cleanup helpers is removal of
- * "goto", and that the "goto" statement can jump between scopes, the
- * expectation is that usage of "goto" and cleanup helpers is never
- * 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.
+ * Lastly, avoid mixing __free() with goto-based resource cleanup in
+ * the same function. This recommendation applies specifically to
+ * resources managed with __free(); it does not preclude using
+ * guard(), scoped_guard(), or ACQUIRE() in a function that uses goto.
*/
/*
--
2.51.1
next reply other threads:[~2026-11-25 16:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 16:12 Przemek Kitszel [this message]
2026-11-25 16:44 ` Peter Zijlstra
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=20261125161205.65809-1-przemyslaw.kitszel@intel.com \
--to=przemyslaw.kitszel@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=brauner@kernel.org \
--cc=d@ilvokhin.com \
--cc=dan.j.williams@intel.com \
--cc=ira.weiny@intel.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®