Skip to contentSkip to conversation

kernel/workqueue: Only unregister a lockdep key if it has been registered first

PATCH New Bart Van Assche 2 participants 2 messages Mar 11, 2019 – Mar 21, 2019 Workqueue

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/workqueue: Only unregister a lockdep key if it has been registered first

Only call wq_unregister_lockdep() if wq_register_lockdep() has been called first. This patch avoids that the following warning is reported:

WARNING: CPU: 1 PID: 6970 at kernel/locking/lockdep.c:4925 lockdep_unregister_key+0x21c/0x4e0

That warning refers to the following source code statement:

	WARN_ON_ONCE(!found);
Cc Tejun Heo <[email protected]>
Cc Qian Cai <[email protected]>
Reported-by [email protected]
Fixes 009bb421b6ce ("workqueue, lockdep: Fix an alloc_workqueue() error path")
---
 kernel/workqueue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/workqueue.c +3 -2
index 4026d1871407..ddee541ea97a 100644
@@ -4266,7 +4266,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
 	INIT_LIST_HEAD(&wq->list);
 
 	if (alloc_and_link_pwqs(wq) < 0)
-		goto err_free_wq;
+		goto err_unreg_lockdep;
 
 	if (wq_online && init_rescuer(wq) < 0)
 		goto err_destroy;
@@ -4292,9 +4292,10 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
 
 	return wq;
 
-err_free_wq:
+err_unreg_lockdep:
 	wq_unregister_lockdep(wq);
 	wq_free_lockdep(wq);
+err_free_wq:
 	free_workqueue_attrs(wq->unbound_attrs);
 	kfree(wq);
 	return NULL;
Signature · 1 line
2.21.0
#1 lore raw

[tip:locking/urgent] workqueue: Only unregister a registered lockdep key

workqueue: Only unregister a registered lockdep key
Commit-ID:  82efcab3b9f3ef59e9713237c6e3c05c3a95c1ae
Gitweb:     https://git.kernel.org/tip/82efcab3b9f3ef59e9713237c6e3c05c3a95c1ae
Author:     Bart Van Assche <[email protected]>
AuthorDate: Mon, 11 Mar 2019 16:02:55 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 21 Mar 2019 12:00:18 +0100

workqueue: Only unregister a registered lockdep key

The recent change to prevent use after free and a memory leak introduced an unconditional call to wq_unregister_lockdep() in the error handling path. If the lockdep key had not been registered yet, then the lockdep core emits a warning.

Only call wq_unregister_lockdep() if wq_register_lockdep() has been called first.

Fixes 009bb421b6ce ("workqueue, lockdep: Fix an alloc_workqueue() error path")
Reported-by [email protected]
Cc Peter Zijlstra <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Qian Cai <[email protected]>
---
 kernel/workqueue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/workqueue.c +3 -2
index 4026d1871407..ddee541ea97a 100644
@@ -4266,7 +4266,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
 	INIT_LIST_HEAD(&wq->list);
 
 	if (alloc_and_link_pwqs(wq) < 0)
-		goto err_free_wq;
+		goto err_unreg_lockdep;
 
 	if (wq_online && init_rescuer(wq) < 0)
 		goto err_destroy;
@@ -4292,9 +4292,10 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
 
 	return wq;
 
-err_free_wq:
+err_unreg_lockdep:
 	wq_unregister_lockdep(wq);
 	wq_free_lockdep(wq);
+err_free_wq:
 	free_workqueue_attrs(wq->unbound_attrs);
 	kfree(wq);
 	return NULL;