From: Bart Van Assche <bvanassche@acm.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
linux-kernel@vger.kernel.org, Marco Elver <elver@google.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
Bart Van Assche <bvanassche@acm.org>,
Nathan Chancellor <nathan@kernel.org>,
Dmitry Ilvokhin <d@ilvokhin.com>,
Christian Brauner <brauner@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH v3 2/3] cleanup: Disable context analysis for __free() helpers
Date: Mon, 16 Nov 2026 14:59:34 -0800 [thread overview]
Message-ID: <d71ef58fdf6958ac524ecd3a81d527af0406c7bd.1794869902.git.bvanassche@acm.org> (raw)
In-Reply-To: <cover.1794869902.git.bvanassche@acm.org>
The __free_##_name() helper functions defined by DEFINE_FREE() call the
free expression that has been passed to DEFINE_FREE(). If that
expression releases a lock, e.g. because it is a call to an unlock
function, the Clang thread-safety analyzer complains because it cannot
know that the variable that is passed to the helper function holds a
lock. This is needed by:
- __drm_for_each_bridge_in_chain_cleanup (include/drm/drm_bridge.h),
used by drm_for_each_bridge_in_chain_scoped() and
drm_for_each_bridge_in_chain_from_scoped().
- netdev_unlock (net/core/dev.h), used by for_each_netdev_lock_scoped().
- netdev_unlock_ops_compat (net/core/dev.h), used by
for_each_netdev_lock_ops_compat_scoped().
Disable context analysis for the __free() helper functions.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
include/linux/cleanup.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index 1fb8058b897d..f6afe80781a4 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -207,8 +207,10 @@
* Without the NULL test it turns into a mess and the compiler can't help us.
*/
-#define DEFINE_FREE(_name, _type, _free) \
- static __always_inline void __free_##_name(void *p) { _type _T = *(_type *)p; _free; }
+#define DEFINE_FREE(_name, _type, _free) \
+ static __always_inline void __free_##_name(void *p) \
+ __context_unsafe(/* _free may release a lock */) \
+ { _type _T = *(_type *)p; _free; }
#define __free(_name) __cleanup(__free_##_name)
next prev parent reply other threads:[~2026-11-16 23:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 22:59 [PATCH 0/3] Fix three Clang context analysis issues Bart Van Assche
2026-11-16 22:59 ` [PATCH v3 1/3] bit_spinlock: Fix the __bitlock() definition Bart Van Assche
2026-11-16 22:59 ` Bart Van Assche [this message]
2026-11-16 22:59 ` [PATCH v3 3/3] srcu: Remove check from srcu_dereference_check() Bart Van Assche
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=d71ef58fdf6958ac524ecd3a81d527af0406c7bd.1794869902.git.bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=d@ilvokhin.com \
--cc=elver@google.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=nathan@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=will@kernel.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®