Skip to contentSkip to conversation

powerpc/pseries/hotplug-cpu: fix memleak in dlpar_cpu_add_by_count

PATCH In review Qinglang Miao 2 participants 3 messages Nov 28, 2020 – Nov 30, 2020 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 powerpc/pseries/hotplug-cpu: fix memleak in dlpar_cpu_add_by_count

kfree(cpu_drcs) should be called when it fails to perform of_find_node_by_path("/cpus") in dlpar_cpu_add_by_count, otherwise there would be a memleak.

In fact, the patch a0ff72f9f5a7 ought to remove kfree in find_dlpar_cpus_to_add rather than dlpar_cpu_add_by_count. I guess there might be a mistake when apply that one.

Fixes a0ff72f9f5a7 ("powerpc/pseries/hotplug-cpu: Remove double free in error path")
---
 arch/powerpc/platforms/pseries/hotplug-cpu.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/platforms/pseries/hotplug-cpu.c +1 -0
index f2837e33b..4bb1c9f2b 100644
@@ -743,6 +743,7 @@ static int dlpar_cpu_add_by_count(u32 cpus_to_add)
 	parent = of_find_node_by_path("/cpus");
 	if (!parent) {
 		pr_warn("Could not find CPU root node in device tree\n");
+		kfree(cpu_drcs);
 		return -1;
 	}
 
Signature · 1 line
2.23.0
#1 lore raw
Quoted 8 lines · Qinglang Miao

kfree(cpu_drcs) should be called when it fails to perform of_find_node_by_path("/cpus") in dlpar_cpu_add_by_count, otherwise there would be a memleak.

In fact, the patch a0ff72f9f5a7 ought to remove kfree in find_dlpar_cpus_to_add rather than dlpar_cpu_add_by_count. I guess there might be a mistake when apply that one.

Quoted 6 lines
Fixes a0ff72f9f5a7 ("powerpc/pseries/hotplug-cpu: Remove double free in error path")
---
 arch/powerpc/platforms/pseries/hotplug-cpu.c | 1 +
 1 file changed, 1 insertion(+)

This is already fixed in my next by:

a40fdaf1420d ("Revert "powerpc/pseries/hotplug-cpu: Remove double free in error path"")

cheers

Quoted 14 lines
arch/powerpc/platforms/pseries/hotplug-cpu.c +1 -0
index f2837e33b..4bb1c9f2b 100644
@@ -743,6 +743,7 @@ static int dlpar_cpu_add_by_count(u32 cpus_to_add)
 	parent = of_find_node_by_path("/cpus");
 	if (!parent) {
 		pr_warn("Could not find CPU root node in device tree\n");
+		kfree(cpu_drcs);
 		return -1;
 	}
 
Signature · 1 line
2.23.0
#2 lore raw
Quoted 38 lines · Michael Ellerman
Quoted 8 lines · Qinglang Miao

kfree(cpu_drcs) should be called when it fails to perform of_find_node_by_path("/cpus") in dlpar_cpu_add_by_count, otherwise there would be a memleak.

In fact, the patch a0ff72f9f5a7 ought to remove kfree in find_dlpar_cpus_to_add rather than dlpar_cpu_add_by_count. I guess there might be a mistake when apply that one.

Quoted 6 lines
Fixes a0ff72f9f5a7 ("powerpc/pseries/hotplug-cpu: Remove double free in error path")
---
  arch/powerpc/platforms/pseries/hotplug-cpu.c | 1 +
  1 file changed, 1 insertion(+)

This is already fixed in my next by:

a40fdaf1420d ("Revert "powerpc/pseries/hotplug-cpu: Remove double free in error path"")

cheers'Revert' sounds resonable to this one, glad to know that.

Quoted 14 lines
arch/powerpc/platforms/pseries/hotplug-cpu.c +1 -0
index f2837e33b..4bb1c9f2b 100644
@@ -743,6 +743,7 @@ static int dlpar_cpu_add_by_count(u32 cpus_to_add)
  	parent = of_find_node_by_path("/cpus");
  	if (!parent) {
  		pr_warn("Could not find CPU root node in device tree\n");
+		kfree(cpu_drcs);
  		return -1;
  	}
 
Signature · 1 line
2.23.0

.