Skip to content

Commit

Permalink
workqueue: fix locking in retry path of maybe_create_worker()
Browse files Browse the repository at this point in the history
maybe_create_worker() mismanaged locking when worker creation fails
and it has to retry.  Fix locking and simplify lock manipulation.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Yong Zhang <yong.zhang@windriver.com>
  • Loading branch information
Tejun Heo committed Jul 14, 2010
1 parent 083b804 commit 9f9c236
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,14 +1442,14 @@ static bool maybe_create_worker(struct global_cwq *gcwq)
if (!need_to_create_worker(gcwq))
return false;
restart:
spin_unlock_irq(&gcwq->lock);

/* if we don't make progress in MAYDAY_INITIAL_TIMEOUT, call for help */
mod_timer(&gcwq->mayday_timer, jiffies + MAYDAY_INITIAL_TIMEOUT);

while (true) {
struct worker *worker;

spin_unlock_irq(&gcwq->lock);

worker = create_worker(gcwq, true);
if (worker) {
del_timer_sync(&gcwq->mayday_timer);
Expand All @@ -1462,15 +1462,13 @@ static bool maybe_create_worker(struct global_cwq *gcwq)
if (!need_to_create_worker(gcwq))
break;

spin_unlock_irq(&gcwq->lock);
__set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(CREATE_COOLDOWN);
spin_lock_irq(&gcwq->lock);

if (!need_to_create_worker(gcwq))
break;
}

spin_unlock_irq(&gcwq->lock);
del_timer_sync(&gcwq->mayday_timer);
spin_lock_irq(&gcwq->lock);
if (need_to_create_worker(gcwq))
Expand Down

0 comments on commit 9f9c236

Please sign in to comment.