[PATCH] workqueue: improve the draining/destroying warning in __queue_work

From: Christoph Hellwig

Date: Tue Nov 03 2026 - 09:44:15 EST


Tell which of the two conditions hit. And to avoid makign the code even
harder to read, move the WARN_ONCE out of the condition triggering it.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
kernel/workqueue.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index f2e8071a6f4e..bea294b00d1f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2428,15 +2428,19 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
lockdep_assert_irqs_disabled();

/*
- * For a draining wq, only works from the same workqueue are
- * allowed. The __WQ_DESTROYING helps to spot the issue that
- * queues a new work item to a wq after destroy_workqueue(wq).
+ * For a draining wq, only works from the same workqueue are allowed.
+ * The __WQ_DESTROYING helps to spot the issue that queues a new work
+ * item to a wq after destroy_workqueue(wq).
*/
if (unlikely(wq->flags & (__WQ_DESTROYING | __WQ_DRAINING) &&
- WARN_ONCE(!is_chained_work(wq), "workqueue: cannot queue %ps on wq %s\n",
- work->func, wq->name))) {
+ !is_chained_work(wq))) {
struct work_offq_data offqd;

+ WARN_ONCE(1, "workqueue: cannot queue %ps on %s wq %s\n",
+ work->func, (wq->flags & __WQ_DESTROYING) ?
+ "destroying" : "draining",
+ wq->name);
+
/*
* State on entry: PENDING is set, work is off-queue (no
* insert_work() has run).
--
2.53.0