[PATCH] powerpc/xics: Check return value of kasprintf in icp_native_map_one_cpu

Kunwu Chan posted 1 patch 2 years ago
arch/powerpc/sysdev/xics/icp-native.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] powerpc/xics: Check return value of kasprintf in icp_native_map_one_cpu
Posted by Kunwu Chan 2 years ago
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 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 f6ec6dba92dc..700b67476a7d 100644
--- a/arch/powerpc/sysdev/xics/icp-native.c
+++ b/arch/powerpc/sysdev/xics/icp-native.c
@@ -236,6 +236,8 @@ static int __init icp_native_map_one_cpu(int hw_id, unsigned long addr,
 	rname = kasprintf(GFP_KERNEL, "CPU %d [0x%x] Interrupt Presentation",
 			  cpu, hw_id);
 
+	if (!rname)
+		return -ENOMEM;
 	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);
-- 
2.34.1
Re: [PATCH] powerpc/xics: Check return value of kasprintf in icp_native_map_one_cpu
Posted by Michael Ellerman 2 years ago
On Wed, 22 Nov 2023 11:06:51 +0800, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure. Ensure the allocation was successful
> by checking the pointer validity.
> 
> 

Applied to powerpc/next.

[1/1] powerpc/xics: Check return value of kasprintf in icp_native_map_one_cpu
      https://git.kernel.org/powerpc/c/45b1ba7e5d1f6881050d558baf9bc74a2ae13930

cheers