Skip to content

Commit 4e9a373

Browse files
Lai Jiangshanhtejun
authored andcommitted
workqueue: Move kthread_flush_worker() out of alloc_and_link_pwqs()
kthread_flush_worker() can't be called with wq_pool_mutex held. Prepare for moving wq_pool_mutex and cpu hotplug lock out of alloc_and_link_pwqs(). Cc: Zqiang <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Lai Jiangshan <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent c5178e6 commit 4e9a373

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

kernel/workqueue.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5467,12 +5467,6 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq)
54675467
}
54685468
cpus_read_unlock();
54695469

5470-
/* for unbound pwq, flush the pwq_release_worker ensures that the
5471-
* pwq_release_workfn() completes before calling kfree(wq).
5472-
*/
5473-
if (ret)
5474-
kthread_flush_worker(pwq_release_worker);
5475-
54765470
return ret;
54775471

54785472
enomem:
@@ -5705,8 +5699,15 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
57055699
return wq;
57065700

57075701
err_free_node_nr_active:
5708-
if (wq->flags & WQ_UNBOUND)
5702+
/*
5703+
* Failed alloc_and_link_pwqs() may leave pending pwq->release_work,
5704+
* flushing the pwq_release_worker ensures that the pwq_release_workfn()
5705+
* completes before calling kfree(wq).
5706+
*/
5707+
if (wq->flags & WQ_UNBOUND) {
5708+
kthread_flush_worker(pwq_release_worker);
57095709
free_node_nr_active(wq->node_nr_active);
5710+
}
57105711
err_unreg_lockdep:
57115712
wq_unregister_lockdep(wq);
57125713
wq_free_lockdep(wq);

0 commit comments

Comments
 (0)