[PATCH] powerpc: Fix potential memory leak in icp_native_map_one_cpu()
From: Xiu Jianfeng
Date: Sat Nov 19 2022 - 01:49:16 EST
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")
Signed-off-by: Xiu Jianfeng <xiujianfeng@xxxxxxxxxx>
---
arch/powerpc/sysdev/xics/icp-native.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/powerpc/sysdev/xics/icp-native.c b/arch/powerpc/sysdev/xics/icp-native.c
index edc17b6b1cc2..126230206350 100644
--- a/arch/powerpc/sysdev/xics/icp-native.c
+++ b/arch/powerpc/sysdev/xics/icp-native.c
@@ -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;
--
2.17.1