Skip to contentSkip to conversation

workqueue: Fix possible memory leaks in wq_numa_init()

PATCH Applied Zhen Lei 3 participants 4 messages Jul 22, 2021 – Jul 29, 2021 Workqueue

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

v2 cover workqueue: Fix possible memory leaks in wq_numa_init()

v1 --> v2:
1. Keep the original "for_each_possible_cpu(cpu)" loop and "cpumask_set_cpu(cpu, tbl[node]);"
2. Remove the comment: /* happens iff arch is bonkers, let's just proceed */

Zhen Lei (1):
workqueue: Fix possible memory leaks in wq_numa_init()

 kernel/workqueue.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/1 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.

---
 kernel/workqueue.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
kernel/workqueue.c +7 -5
index 50142fc08902..79cc470bd9ce 100644
@@ -5896,6 +5896,13 @@ static void __init wq_numa_init(void)
 		return;
 	}
 
+	for_each_possible_cpu(cpu) {
+		if (WARN_ON(cpu_to_node(cpu) == NUMA_NO_NODE)) {
+			pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
+			return;
+		}
+	}
+
 	wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs();
 	BUG_ON(!wq_update_unbound_numa_attrs_buf);
 
@@ -5913,11 +5920,6 @@ static void __init wq_numa_init(void)
 
 	for_each_possible_cpu(cpu) {
 		node = cpu_to_node(cpu);
-		if (WARN_ON(node == NUMA_NO_NODE)) {
-			pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
-			/* happens iff arch is bonkers, let's just proceed */
-			return;
-		}
 		cpumask_set_cpu(cpu, tbl[node]);
 	}
 
Signature · 1 line
2.25.1
reviewer Reviewed-by on v2 1/1
#2 lore raw
Quoted 43 lines · Zhen Lei

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.

---
 kernel/workqueue.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
kernel/workqueue.c +7 -6
index 50142fc08902..79cc470bd9ce 100644
@@ -5896,6 +5896,13 @@ static void __init wq_numa_init(void)
                return;
        }
 
+       for_each_possible_cpu(cpu) {
+               if (WARN_ON(cpu_to_node(cpu) == NUMA_NO_NODE)) {
+                       pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
+                       return;
+               }
+       }
+
        wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs();
        BUG_ON(!wq_update_unbound_numa_attrs_buf);
 
@@ -5913,11 +5920,6 @@ static void __init wq_numa_init(void)
 
        for_each_possible_cpu(cpu) {
                node = cpu_to_node(cpu);
-               if (WARN_ON(node == NUMA_NO_NODE)) {
-                       pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu);
-                       /* happens iff arch is bonkers, let's just proceed */
-                       return;
-               }
                cpumask_set_cpu(cpu, tbl[node]);
        }
 
--

2.25.1

maintainer Applied
#3 lore raw
In reply to Zhen Lei
Quoted 5 lines · Zhen Lei

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.

Applied to wq/for-5.15.

Thanks.

Signature · 1 line
tejun