Thread (28 messages) 28 messages, 7 authors, 9d ago

[PATCH 10/17] klist: assert static storage for DEFINE_KLIST()

flat view
COOLING9d

From: Yury Norov <hidden>
Date: 2026-09-15 03:14:03
Also in: linux-fsdevel, linux-mm, linux-rt-devel, linuxppc-dev, lkml, llvm, rcu, virtualization
Subsystem: the rest · Maintainer: Linus Torvalds

DEFINE_KLIST() statically initializes k_lock, relying on the object
address as a persistent lockdep class key. An automatic local klist must
instead use klist_init().

Add ASSERT_STATIC_STORAGE() to enforce this requirement at compile time.
Keep KLIST_INIT() available for embedded objects.

Assisted-by: OpenAI Codex
Signed-off-by: Yury Norov <redacted>
---
 include/linux/klist.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/linux/klist.h b/include/linux/klist.h
index b0f238f20dbb..5848363242b6 100644
--- a/include/linux/klist.h
+++ b/include/linux/klist.h
@@ -10,6 +10,7 @@
 #ifndef _LINUX_KLIST_H
 #define _LINUX_KLIST_H
 
+#include <linux/compiler.h>
 #include <linux/spinlock.h>
 #include <linux/kref.h>
 #include <linux/list.h>
@@ -29,7 +30,8 @@ struct klist {
 	  .put		= _put, }
 
 #define DEFINE_KLIST(_name, _get, _put)					\
-	struct klist _name = KLIST_INIT(_name, _get, _put)
+	struct klist _name = KLIST_INIT(_name, _get, _put);		\
+	ASSERT_STATIC_STORAGE(_name)
 
 extern void klist_init(struct klist *k, void (*get)(struct klist_node *),
 		       void (*put)(struct klist_node *));
-- 
2.53.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help