DEFINE_KTHREAD_DELAYED_WORK() embeds a statically initialized timer.
Using the declaration for an automatic object violates the timer's
debugobjects storage contract.

Add ASSERT_STATIC_STORAGE() to reject such declarations. Plain
DEFINE_KTHREAD_WORK() has no embedded timer or static lockdep map and
remains usable for automatic objects with an appropriately bounded
lifetime.

Assisted-by: OpenAI Codex
Signed-off-by: Yury Norov <[email protected]>
---
 include/linux/kthread.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index a01a474719a7..faa9dfb2f6cf 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -2,6 +2,7 @@
 #ifndef _LINUX_KTHREAD_H
 #define _LINUX_KTHREAD_H
 /* Simple interface for creating and stopping kernel threads without mess. */
+#include <linux/compiler.h>
 #include <linux/err.h>
 #include <linux/sched.h>
 
@@ -179,7 +180,8 @@ struct kthread_delayed_work {
 
 #define DEFINE_KTHREAD_DELAYED_WORK(dwork, fn)                         \
        struct kthread_delayed_work dwork =                             \
-               KTHREAD_DELAYED_WORK_INIT(dwork, fn)
+               KTHREAD_DELAYED_WORK_INIT(dwork, fn);                   \
+       ASSERT_STATIC_STORAGE(dwork)
 
 extern void __kthread_init_worker(struct kthread_worker *worker,
                        const char *name, struct lock_class_key *key);
-- 
2.53.0


Reply via email to