From: Su Hui <suhui@nfschina.com>
To: paulmck@kernel.org
Cc: dave@stgolabs.net, josh@joshtriplett.org, frederic@kernel.org,
neeraj.upadhyay@kernel.org, joel@joelfernandes.org,
boqun.feng@gmail.com, urezki@gmail.com, rostedt@goodmis.org,
mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com,
qiang.zhang1211@gmail.com, linux-kernel@vger.kernel.org,
rcu@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH] rcuscale: using kmalloc_array() to relpace kmalloc()
Date: Tue, 22 Apr 2025 09:37:39 +0800 [thread overview]
Message-ID: <576c236f-3c12-42d9-b2cc-7367339fb37e@nfschina.com> (raw)
In-Reply-To: <7743ff8a-1492-4191-95ec-abcb53001b83@paulmck-laptop>
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@nfschina.com>
> 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
>>
>>
next prev parent reply other threads:[~2025-04-22 1:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-21 6:15 Su Hui
2025-04-21 13:49 ` Paul E. McKenney
2025-04-22 1:37 ` Su Hui [this message]
2025-04-22 1:51 ` [PATCH v2] rcuscale: using kcalloc() " Su Hui
2025-04-22 17:58 ` Paul E. McKenney
2025-04-22 22:55 ` Joel Fernandes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=576c236f-3c12-42d9-b2cc-7367339fb37e@nfschina.com \
--to=suhui@nfschina.com \
--cc=boqun.feng@gmail.com \
--cc=dave@stgolabs.net \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=qiang.zhang1211@gmail.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®