public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] workqueue: do a sanity check on new work
@ 2012-04-13 14:35 Dan Carpenter
  2012-04-13 16:39 ` Tejun Heo
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2012-04-13 14:35 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-kernel, Matt Renzelmann

There may be a better way to do this.  If someone tries to call
shedule_work() on a work_struck before doing an INIT_WORK() then we
hit the BUG_ON(!list_empty(&work->entry)) in __queue_work() and hang.
Instead of that, we could just print a stack dump and return.

It only works if the work->func is NULL at the start but a lot of these
things get initialized with kzalloc() so it probably catches most of
them.

Reported-by: Matt Renzelmann <mjr@cs.wisc.edu>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 5abf42f..45be34f 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1088,6 +1088,11 @@ queue_work_on(int cpu, struct workqueue_struct *wq, struct work_struct *work)
 {
 	int ret = 0;
 
+	if (!work->func) {
+		WARN_ON(1);
+		return 1;
+	}
+
 	if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
 		__queue_work(cpu, wq, work);
 		ret = 1;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-16 21:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-13 14:35 [RFC] workqueue: do a sanity check on new work Dan Carpenter
2012-04-13 16:39 ` Tejun Heo
2012-04-13 18:58   ` Dan Carpenter
2012-04-13 19:06   ` [patch v2] workqueue: change BUG_ON() to WARN_ON() Dan Carpenter
2012-04-16 21:57     ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox