Skip to content

Commit f728c4a

Browse files
Zhen Leihtejun
authored andcommitted
workqueue: Fix possible memory leaks in wq_numa_init()
In error handling branch "if (WARN_ON(node == NUMA_NO_NODE))", the previously allocated memories are not released. Doing this before allocating memory eliminates memory leaks. tj: Note that the condition only occurs when the arch code is pretty broken and the WARN_ON might as well be BUG_ON(). Signed-off-by: Zhen Lei <[email protected]> Reviewed-by: Lai Jiangshan <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 7e96bf4 commit f728c4a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

kernel/workqueue.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5902,6 +5902,13 @@ static void __init wq_numa_init(void)
59025902
return;
59035903
}
59045904

5905+
for_each_possible_cpu(cpu) {
5906+
if (WARN_ON(cpu_to_node(cpu) == NUMA_NO_NODE)) {
5907+
pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
5908+
return;
5909+
}
5910+
}
5911+
59055912
wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs();
59065913
BUG_ON(!wq_update_unbound_numa_attrs_buf);
59075914

@@ -5919,11 +5926,6 @@ static void __init wq_numa_init(void)
59195926

59205927
for_each_possible_cpu(cpu) {
59215928
node = cpu_to_node(cpu);
5922-
if (WARN_ON(node == NUMA_NO_NODE)) {
5923-
pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
5924-
/* happens iff arch is bonkers, let's just proceed */
5925-
return;
5926-
}
59275929
cpumask_set_cpu(cpu, tbl[node]);
59285930
}
59295931

0 commit comments

Comments
 (0)