Skip to content

Commit 3e15ccc

Browse files
qianfengrongpaulmckrcu
authored andcommitted
rcutorture: Use kcalloc() instead of kzalloc()
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>
1 parent 51c285b commit 3e15ccc

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel/rcu/rcutorture.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,12 +1572,12 @@ rcu_torture_writer(void *arg)
15721572
return 0;
15731573
}
15741574
if (cur_ops->poll_active > 0) {
1575-
ulo = kzalloc(cur_ops->poll_active * sizeof(ulo[0]), GFP_KERNEL);
1575+
ulo = kcalloc(cur_ops->poll_active, sizeof(*ulo), GFP_KERNEL);
15761576
if (!WARN_ON(!ulo))
15771577
ulo_size = cur_ops->poll_active;
15781578
}
15791579
if (cur_ops->poll_active_full > 0) {
1580-
rgo = kzalloc(cur_ops->poll_active_full * sizeof(rgo[0]), GFP_KERNEL);
1580+
rgo = kcalloc(cur_ops->poll_active_full, sizeof(*rgo), GFP_KERNEL);
15811581
if (!WARN_ON(!rgo))
15821582
rgo_size = cur_ops->poll_active_full;
15831583
}

0 commit comments

Comments
 (0)