]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
refscale: Use kcalloc() instead of kzalloc()
authorQianfeng Rong <rongqianfeng@vivo.com>
Thu, 21 Aug 2025 13:41:17 +0000 (21:41 +0800)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 22 Aug 2025 13:26:22 +0000 (06:26 -0700)
Use kcalloc() in main_func() to gain built-in overflow protection, making
memory allocation safer when calculating allocation size compared to
explicit multiplication.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/refscale.c

index df646e0694a8ccf36e20bbe417724da2efceb5f2..5840fac06feb7d4930f530629ca9ade9730768dd 100644 (file)
@@ -1021,7 +1021,7 @@ static int main_func(void *arg)
        set_user_nice(current, MAX_NICE);
 
        VERBOSE_SCALEOUT("main_func task started");
-       result_avg = kzalloc(nruns * sizeof(*result_avg), GFP_KERNEL);
+       result_avg = kcalloc(nruns, sizeof(*result_avg), GFP_KERNEL);
        buf = kzalloc(800 + 64, GFP_KERNEL);
        if (!result_avg || !buf) {
                SCALEOUT_ERRSTRING("out of memory");