[PATCH 11/17] workqueue: assert static storage for work declarations
From: Yury Norov
Date: Mon Sep 14 2026 - 23:20:56 EST
Static work initializers use the work address as a lockdep class key and
mark the work item static for debugobjects. Automatic objects require
on-stack initialization instead.
Apply ASSERT_STATIC_STORAGE() to DECLARE_WORK(), DECLARE_DELAYED_WORK()
and DECLARE_DEFERRABLE_WORK(). Automatic objects must use the matching
INIT_*_ONSTACK() API and destroy the on-stack debugobjects before leaving
scope. Keep the underlying initializers available for embedded objects.
Assisted-by: OpenAI Codex
Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>
---
include/linux/workqueue.h | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index c8a36423cb34..433c9801d9c5 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -6,6 +6,7 @@
#ifndef _LINUX_WORKQUEUE_H
#define _LINUX_WORKQUEUE_H
+#include <linux/compiler.h>
#include <linux/alloc_tag.h>
#include <linux/timer.h>
#include <linux/linkage.h>
@@ -250,13 +251,16 @@ struct execute_work {
}
#define DECLARE_WORK(n, f) \
- struct work_struct n = __WORK_INITIALIZER(n, f)
+ struct work_struct n = __WORK_INITIALIZER(n, f); \
+ ASSERT_STATIC_STORAGE(n)
#define DECLARE_DELAYED_WORK(n, f) \
- struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, 0)
+ struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, 0); \
+ ASSERT_STATIC_STORAGE(n)
#define DECLARE_DEFERRABLE_WORK(n, f) \
- struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, TIMER_DEFERRABLE)
+ struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, TIMER_DEFERRABLE); \
+ ASSERT_STATIC_STORAGE(n)
#ifdef CONFIG_DEBUG_OBJECTS_WORK
extern void __init_work(struct work_struct *work, int onstack);
--
2.53.0