On 2025/4/21 21:49, Paul E. McKenney wrote:
On Mon, Apr 21, 2025 at 02:15:09PM +0800, Su Hui wrote:
It's safer to using kmalloc_array() because it can prevent overflow
problem.
Signed-off-by: Su Hui <suhui@xxxxxxxxxxxx>
Thank you!
But isn't kcalloc just a wrapper around kmalloc_array() anyway?
Yes, and kcalloc() add the _GFP_ZERO flag. I can send a v2 patch with
kcalloc().
Thanks for your suggestion.
Su Hui
---
kernel/rcu/rcuscale.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
index 0f3059b1b80d..cbe2195f08d6 100644
--- a/kernel/rcu/rcuscale.c
+++ b/kernel/rcu/rcuscale.c
@@ -762,7 +762,7 @@ kfree_scale_thread(void *arg)
}
for (i = 0; i < kfree_alloc_num; i++) {
- alloc_ptr = kmalloc(kfree_mult * sizeof(struct kfree_obj), GFP_KERNEL);
+ alloc_ptr = kmalloc_array(kfree_mult, sizeof(struct kfree_obj), GFP_KERNEL);
if (!alloc_ptr)
return -ENOMEM;
--
2.30.2