[tip: locking/urgent] cleanup: Disable context analysis for __free() helpers

tip-bot2 for Bart Van Assche posted 1 patch 11 hours ago
There is a newer version of this series
include/linux/cleanup.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[tip: locking/urgent] cleanup: Disable context analysis for __free() helpers
Posted by tip-bot2 for Bart Van Assche 11 hours ago
The following commit has been merged into the locking/urgent branch of tip:

Commit-ID:     f7c70c05bba097d99dd06346b037f01c5ab44fbf
Gitweb:        https://git.kernel.org/tip/f7c70c05bba097d99dd06346b037f01c5ab44fbf
Author:        Bart Van Assche <bvanassche@acm.org>
AuthorDate:    Wed, 18 Nov 2026 15:09:58 -08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 22 Nov 2026 16:03:03 +01:00

cleanup: Disable context analysis for __free() helpers

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 via
__context_unsafe().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Marco Elver <elver@google.com>
Link: https://patch.msgid.link/d87cfee3aa630885cbdb95f0f918e86a1263c2ec.1795043161.git.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 1fb8058..1e09aea 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)