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 <[email protected]> --- 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
