]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kallsyms: use kmalloc_array() instead of kmalloc()
authorSahil Chandna <chandna.linuxkernel@gmail.com>
Fri, 26 Sep 2025 07:50:53 +0000 (13:20 +0530)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 28 Sep 2025 18:36:14 +0000 (11:36 -0700)
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.

Link: https://lkml.kernel.org/r/20250926075053.25615-1-chandna.linuxkernel@gmail.com
Signed-off-by: Sahil Chandna <chandna.linuxkernel@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: David Hunter <david.hunter.linux@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/kallsyms_selftest.c

index cf4af5728307b3a0c76655ea34d74ca11275684b..2b082a7e24a20a8783bc14f396721b38ac3a981f 100644 (file)
@@ -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;