[PATCH 02/17] locking/rtmutex: assert static storage for DEFINE_RT_MUTEX()

From
Yury Norov <hidden>
Date
2026-09-15 03:04:05
Also in
linux-fsdevel, linux-mm, linux-rt-devel, lkml, llvm, netdev, rcu, virtualization
Reply to
Yury Norov, 2026-09-15
DEFINE_RT_MUTEX() statically initializes both the mutex lockdep map and
its internal wait lock. An automatic local object cannot supply the
persistent class key expected by this initialization.

Add ASSERT_STATIC_STORAGE() to reject automatic declarations. Such mutexes
must use rt_mutex_init(); file-scope and static local definitions remain
valid. Leave __RT_MUTEX_INITIALIZER() available for embedded objects.

Assisted-by: OpenAI Codex
Signed-off-by: Yury Norov <redacted>
---
 include/linux/rtmutex.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h
index 9e1f012f89db..495509d82c88 100644
--- a/include/linux/rtmutex.h
+++ b/include/linux/rtmutex.h
@@ -105,7 +105,8 @@ do { \
 }
 
 #define DEFINE_RT_MUTEX(mutexname) \
-	struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
+	struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname);	\
+	ASSERT_STATIC_STORAGE(mutexname)
 
 extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
 
-- 
2.53.0

Thread (29 messages) 29 messages, 7 authors, last reply 3d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help