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

Change sizeof(ulo[0]) and sizeof(rgo[0]) to sizeof(*ulo) and sizeof(*rgo),
as this is more consistent with coding conventions.

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

index b8a684459381f21bcbb96793006da251f524c812..29fe3c01312f60ebac23a99aaaf24d619d54b73b 100644 (file)
@@ -1572,12 +1572,12 @@ rcu_torture_writer(void *arg)
                return 0;
        }
        if (cur_ops->poll_active > 0) {
-               ulo = kzalloc(cur_ops->poll_active * sizeof(ulo[0]), GFP_KERNEL);
+               ulo = kcalloc(cur_ops->poll_active, sizeof(*ulo), GFP_KERNEL);
                if (!WARN_ON(!ulo))
                        ulo_size = cur_ops->poll_active;
        }
        if (cur_ops->poll_active_full > 0) {
-               rgo = kzalloc(cur_ops->poll_active_full * sizeof(rgo[0]), GFP_KERNEL);
+               rgo = kcalloc(cur_ops->poll_active_full, sizeof(*rgo), GFP_KERNEL);
                if (!WARN_ON(!rgo))
                        rgo_size = cur_ops->poll_active_full;
        }