Skip to contentSkip to conversation

kallsyms: use kmalloc_array() instead of kmalloc()

PATCH Applied Sahil Chandna 1 participant 1 message Sep 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kallsyms: use kmalloc_array() instead of kmalloc()

Replace kmalloc(sizeof(*stat) * 2, GFP_KERNEL) with kmalloc_array(2, sizeof(*stat), GFP_KERNEL) to prevent potential overflow, as recommended in Documentation/process/deprecated.rst.

---
 kernel/kallsyms_selftest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kallsyms_selftest.c +1 -1
index cf4af5728307..2b082a7e24a2 100644
@@ -264,7 +264,7 @@ static int test_kallsyms_basic_function(void)
 	char namebuf[KSYM_NAME_LEN];
 	struct test_stat *stat, *stat2;
 
-	stat = kmalloc(sizeof(*stat) * 2, GFP_KERNEL);
+	stat = kmalloc_array(2, sizeof(*stat), GFP_KERNEL);
 	if (!stat)
 		return -ENOMEM;
 	stat2 = stat + 1;
Signature · 1 line
2.50.1