[PATCH] workqueue: trigger WARN if queue_delayed_work() is called with NULL @wq

From: Tejun Heo
Date: Mon Mar 06 2017 - 15:33:42 EST


If queue_delayed_work() gets called with NULL @wq, the kernel will
oops asynchronuosly on timer expiration which isn't too helpful in
tracking down the offender. This actually happened with smc.

__queue_delayed_work() already does several input sanity checks
synchronously. Add NULL @wq check.

Reported-by: Dave Jones <davej@xxxxxxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/20170227171439.jshx3qplflyrgcv7@xxxxxxxxxxxxxxxxx
Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
---
kernel/workqueue.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 072cbc9..c0168b7 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1507,6 +1507,7 @@ 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 ||
timer->data != (unsigned long)dwork);
WARN_ON_ONCE(timer_pending(timer));
--
2.9.3