* [PATCH] workqueue: check for NULL wq in queue_delayed_work_on()
@ 2026-03-16 18:03 baichen
2026-03-17 17:54 ` Tejun Heo
2026-03-17 17:56 ` [PATCH wq/for-7.1] workqueue: Remove NULL wq WARN in __queue_delayed_work() Tejun Heo
0 siblings, 2 replies; 4+ messages in thread
From: baichen @ 2026-03-16 18:03 UTC (permalink / raw)
To: linux-kernel; +Cc: tj, jiangshanlai, baichen
If queue_delayed_work() is called with a NULL wq, the existing
WARN_ON_ONCE(!wq) in __queue_delayed_work() only prints a warning
but doesn't prevent the subsequent NULL pointer dereference when
accessing wq->flags, causing a panic.
Add a NULL check at the beginning of queue_delayed_work_on() to
catch this error early, print a warning with stack dump, and return
false to the caller instead of crashing later.
Additionally, if the delay time is relatively long or there are too many
kernel log prints in a short time, the previous warning message may be
overwritten, making such issues difficult to debug. Relying on kernel log
alone makes it impossible to diagnose this issue, and one must resort to
fulldump to solve it.
Cc: Tejun Heo <tj@kernel.org>,
Lai Jiangshan <jiangshanlai@gmail.com>,
linux-kernel@vger.kernel.org
Signed-off-by: baichen.zhang <ttdxba@gmail.com>
---
kernel/workqueue.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index cd5171208964..6cf0c5eefa07 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2510,7 +2510,6 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
struct timer_list *timer = &dwork->timer;
struct work_struct *work = &dwork->work;
- WARN_ON_ONCE(!wq);
WARN_ON_ONCE(timer->function != delayed_work_timer_fn);
WARN_ON_ONCE(timer_pending(timer));
WARN_ON_ONCE(!list_empty(&work->entry));
@@ -2569,6 +2568,14 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
bool ret = false;
unsigned long irq_flags;
+ if (unlikely(!wq)) {
+ WARN_ON_ONCE(1);
+ pr_warn("workqueue: %s() called with NULL wq, dumping stack:\n",
+ __func__);
+ dump_stack();
+ return false;
+ }
+
/* read the comment in __queue_work() */
local_irq_save(irq_flags);
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] workqueue: check for NULL wq in queue_delayed_work_on()
@ 2026-03-17 12:11 kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-03-17 12:11 UTC (permalink / raw)
To: oe-kbuild
::::::
:::::: Manual check reason: "high confidence checkpatch report"
::::::
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20260316180300.66423-1-ttdxba@gmail.com>
References: <20260316180300.66423-1-ttdxba@gmail.com>
TO: baichen <ttdxba@gmail.com>
TO: linux-kernel@vger.kernel.org
Hi baichen,
kernel test robot noticed the following build warnings:
[auto build test WARNING on v7.0-rc2]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/baichen/workqueue-check-for-NULL-wq-in-queue_delayed_work_on/20260317-023327
base: v7.0-rc2
patch link: https://lore.kernel.org/r/20260316180300.66423-1-ttdxba%40gmail.com
patch subject: [PATCH] workqueue: check for NULL wq in queue_delayed_work_on()
:::::: branch date: 17 hours ago
:::::: commit date: 17 hours ago
reproduce: (https://download.01.org/0day-ci/archive/20260317/202603171334.DwWhBDi0-lkp@intel.com/reproduce)
# many are suggestions rather than must-fix
WARNING:BAD_SIGN_OFF: Unexpected content after email: 'Tejun Heo <tj@kernel.org>,', should be: 'Tejun Heo <tj@kernel.org>'
#19:
Cc: Tejun Heo <tj@kernel.org>,
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] workqueue: check for NULL wq in queue_delayed_work_on()
2026-03-16 18:03 [PATCH] workqueue: check for NULL wq in queue_delayed_work_on() baichen
@ 2026-03-17 17:54 ` Tejun Heo
2026-03-17 17:56 ` [PATCH wq/for-7.1] workqueue: Remove NULL wq WARN in __queue_delayed_work() Tejun Heo
1 sibling, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2026-03-17 17:54 UTC (permalink / raw)
To: baichen; +Cc: linux-kernel, Lai Jiangshan
Hello,
Calling workqueue APIs with a NULL wq is always a caller bug and adding
NULL checks to all APIs isn't the right approach. The WARN was there as a
debug aid but it doesn't actually prevent the crash, so it's misleading.
I'm removing it instead.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH wq/for-7.1] workqueue: Remove NULL wq WARN in __queue_delayed_work()
2026-03-16 18:03 [PATCH] workqueue: check for NULL wq in queue_delayed_work_on() baichen
2026-03-17 17:54 ` Tejun Heo
@ 2026-03-17 17:56 ` Tejun Heo
1 sibling, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2026-03-17 17:56 UTC (permalink / raw)
To: linux-kernel; +Cc: Lai Jiangshan, baichen
Remove the WARN_ON_ONCE(!wq) which doesn't serve any useful purpose.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
Applied to wq/for-7.1.
kernel/workqueue.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index c1743b20a524..63acaa3e1d6a 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2510,7 +2510,6 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
struct timer_list *timer = &dwork->timer;
struct work_struct *work = &dwork->work;
- WARN_ON_ONCE(!wq);
WARN_ON_ONCE(timer->function != delayed_work_timer_fn);
WARN_ON_ONCE(timer_pending(timer));
WARN_ON_ONCE(!list_empty(&work->entry));
--
tejun
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-17 17:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 18:03 [PATCH] workqueue: check for NULL wq in queue_delayed_work_on() baichen
2026-03-17 17:54 ` Tejun Heo
2026-03-17 17:56 ` [PATCH wq/for-7.1] workqueue: Remove NULL wq WARN in __queue_delayed_work() Tejun Heo
-- strict thread matches above, loose matches on Subject: below --
2026-03-17 12:11 [PATCH] workqueue: check for NULL wq in queue_delayed_work_on() kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.