mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: baichen <ttdxba@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: tj@kernel.org, jiangshanlai@gmail.com, baichen <ttdxba@gmail.com>
Subject: [PATCH] workqueue: check for NULL wq in queue_delayed_work_on()
Date: Tue, 17 Mar 2026 02:03:00 +0800	[thread overview]
Message-ID: <20260316180300.66423-1-ttdxba@gmail.com> (raw)

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


             reply	other threads:[~2026-03-16 18:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-16 18:03 baichen [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260316180300.66423-1-ttdxba@gmail.com \
    --to=ttdxba@gmail.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®