Skip to contentSkip to conversation

powerpc: Fix potential memory leak in icp_native_map_one_cpu()

PATCH New Xiu Jianfeng 1 participant 1 message Nov 19, 2022 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: Fix potential memory leak in icp_native_map_one_cpu()

Before return error, it has allocated memory by kasprintf() and save it in @rname, may cause a memory leak issue, fix it.

Fixes 0b05ac6e2480 ("powerpc/xics: Rewrite XICS driver")
---
 arch/powerpc/sysdev/xics/icp-native.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/sysdev/xics/icp-native.c +2 -0
index edc17b6b1cc2..126230206350 100644
@@ -239,6 +239,7 @@ static int __init icp_native_map_one_cpu(int hw_id, unsigned long addr,
 	if (!request_mem_region(addr, size, rname)) {
 		pr_warn("icp_native: Could not reserve ICP MMIO for CPU %d, interrupt server #0x%x\n",
 			cpu, hw_id);
+		kfree(rname);
 		return -EBUSY;
 	}
 
@@ -248,6 +249,7 @@ static int __init icp_native_map_one_cpu(int hw_id, unsigned long addr,
 		pr_warn("icp_native: Failed ioremap for CPU %d, interrupt server #0x%x, addr %#lx\n",
 			cpu, hw_id, addr);
 		release_mem_region(addr, size);
+		kfree(rname);
 		return -ENOMEM;
 	}
 	return 0;
Signature · 1 line
2.17.1