Move the per-cpu pwq allocation loop out of alloc_and_link_pwqs() into a helper. The inner allocation-failure path now returns -ENOMEM and the caller jumps to the existing enomem cleanup, equivalent to the previous goto. No functional change.
Showing the changes to kernel/workqueue.c (1 of 1 file). Show all
Unified · Split
| @@ -5666,6 +5666,28 @@ out_unlock: · 5665 unmodified lines | |||
| 5666 | put_pwq_unlocked(old_pwq); | 5666 | put_pwq_unlocked(old_pwq); |
| 5667 | } | 5667 | } |
| 5668 | 5668 | ||
| 5669 | static int alloc_and_link_percpu_pwqs(struct workqueue_struct *wq) | ||
| 5670 | { | ||
| 5671 | int cpu; | ||
| 5672 | |||
| 5673 | for_each_possible_cpu(cpu) { | ||
| 5674 | struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu); | ||
| 5675 | struct worker_pool *pool = get_percpu_pool(wq, cpu); | ||
| 5676 | |||
| 5677 | *pwq_p = kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, pool->node); | ||
| 5678 | if (!*pwq_p) | ||
| 5679 | return -ENOMEM; | ||
| 5680 | |||
| 5681 | init_pwq(*pwq_p, wq, pool); | ||
| 5682 | |||
| 5683 | mutex_lock(&wq->mutex); | ||
| 5684 | link_pwq(*pwq_p); | ||
| 5685 | mutex_unlock(&wq->mutex); | ||
| 5686 | } | ||
| 5687 | |||
| 5688 | return 0; | ||
| 5689 | } | ||
| 5690 | |||
| 5669 | static int alloc_and_link_pwqs(struct workqueue_struct *wq) | 5691 | static int alloc_and_link_pwqs(struct workqueue_struct *wq) |
| 5670 | { | 5692 | { |
| 5671 | bool highpri = wq->flags & WQ_HIGHPRI; | 5693 | bool highpri = wq->flags & WQ_HIGHPRI; |
| @@ -5678,25 +5700,8 @@ static int alloc_and_link_pwqs(struct workqueue_struct *wq) · 6 unmodified lines | |||
| 5678 | goto enomem; | 5700 | goto enomem; |
| 5679 | 5701 | ||
| 5680 | if (!(wq->flags & WQ_UNBOUND)) { | 5702 | if (!(wq->flags & WQ_UNBOUND)) { |
| 5681 | for_each_possible_cpu(cpu) { | 5703 | ret = alloc_and_link_percpu_pwqs(wq); |
| 5682 | struct pool_workqueue **pwq_p = per_cpu_ptr(wq->cpu_pwq, cpu); | 5704 | } else if (wq->flags & __WQ_ORDERED) { |
| 5683 | struct worker_pool *pool = get_percpu_pool(wq, cpu); | ||
| 5684 | |||
| 5685 | *pwq_p = kmem_cache_alloc_node(pwq_cache, GFP_KERNEL, | ||
| 5686 | pool->node); | ||
| 5687 | if (!*pwq_p) | ||
| 5688 | goto enomem; | ||
| 5689 | |||
| 5690 | init_pwq(*pwq_p, wq, pool); | ||
| 5691 | |||
| 5692 | mutex_lock(&wq->mutex); | ||
| 5693 | link_pwq(*pwq_p); | ||
| 5694 | mutex_unlock(&wq->mutex); | ||
| 5695 | } | ||
| 5696 | return 0; | ||
| 5697 | } | ||
| 5698 | |||
| 5699 | if (wq->flags & __WQ_ORDERED) { | ||
| 5700 | struct pool_workqueue *dfl_pwq; | 5705 | struct pool_workqueue *dfl_pwq; |
| 5701 | 5706 | ||
| 5702 | ret = apply_workqueue_attrs_locked(wq, ordered_wq_attrs[highpri]); | 5707 | ret = apply_workqueue_attrs_locked(wq, ordered_wq_attrs[highpri]); |