* [PATCH 0/2] rcu: Use kcalloc() instead of kzalloc()
@ 2025-08-21 13:41 Qianfeng Rong
2025-08-21 13:41 ` [PATCH 1/2] rcutorture: " Qianfeng Rong
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-21 13:41 UTC (permalink / raw)
To: Davidlohr Bueso, Paul E. McKenney, Josh Triplett,
Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes, Boqun Feng,
Uladzislau Rezki, Steven Rostedt, Mathieu Desnoyers,
Lai Jiangshan, Zqiang, open list:TORTURE-TEST MODULES,
open list:READ-COPY UPDATE (RCU)
Cc: Qianfeng Rong
Replace kzalloc() with kcalloc() in kernel/rcu. As noted in the kernel
documentation [1], open-coded multiplication in allocator arguments is
discouraged because it can lead to integer overflow.
Use kcalloc() to gain built-in overflow protection, making memory
allocation safer when calculating allocation size compared to explicit
multiplication.
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments #1
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Qianfeng Rong (2):
rcutorture: Use kcalloc() instead of kzalloc()
refscale: Use kcalloc() instead of kzalloc()
kernel/rcu/rcutorture.c | 4 ++--
kernel/rcu/refscale.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] rcutorture: Use kcalloc() instead of kzalloc()
2025-08-21 13:41 [PATCH 0/2] rcu: Use kcalloc() instead of kzalloc() Qianfeng Rong
@ 2025-08-21 13:41 ` Qianfeng Rong
2025-08-21 13:41 ` [PATCH 2/2] refscale: " Qianfeng Rong
2025-08-21 15:27 ` [PATCH 0/2] rcu: " Paul E. McKenney
2 siblings, 0 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-21 13:41 UTC (permalink / raw)
To: Davidlohr Bueso, Paul E. McKenney, Josh Triplett,
Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes, Boqun Feng,
Uladzislau Rezki, Steven Rostedt, Mathieu Desnoyers,
Lai Jiangshan, Zqiang, open list:TORTURE-TEST MODULES,
open list:READ-COPY UPDATE (RCU)
Cc: Qianfeng Rong
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>
---
kernel/rcu/rcutorture.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 7a893d51d02b..60cac761efc9 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1571,12 +1571,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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] refscale: Use kcalloc() instead of kzalloc()
2025-08-21 13:41 [PATCH 0/2] rcu: Use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-21 13:41 ` [PATCH 1/2] rcutorture: " Qianfeng Rong
@ 2025-08-21 13:41 ` Qianfeng Rong
2025-08-21 15:27 ` [PATCH 0/2] rcu: " Paul E. McKenney
2 siblings, 0 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-21 13:41 UTC (permalink / raw)
To: Davidlohr Bueso, Paul E. McKenney, Josh Triplett,
Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes, Boqun Feng,
Uladzislau Rezki, Steven Rostedt, Mathieu Desnoyers,
Lai Jiangshan, Zqiang, open list:TORTURE-TEST MODULES,
open list:READ-COPY UPDATE (RCU)
Cc: Qianfeng Rong
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>
---
kernel/rcu/refscale.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
index df646e0694a8..5840fac06feb 100644
--- a/kernel/rcu/refscale.c
+++ b/kernel/rcu/refscale.c
@@ -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");
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] rcu: Use kcalloc() instead of kzalloc()
2025-08-21 13:41 [PATCH 0/2] rcu: Use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-21 13:41 ` [PATCH 1/2] rcutorture: " Qianfeng Rong
2025-08-21 13:41 ` [PATCH 2/2] refscale: " Qianfeng Rong
@ 2025-08-21 15:27 ` Paul E. McKenney
2 siblings, 0 replies; 4+ messages in thread
From: Paul E. McKenney @ 2025-08-21 15:27 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Davidlohr Bueso, Josh Triplett, Frederic Weisbecker,
Neeraj Upadhyay, Joel Fernandes, Boqun Feng, Uladzislau Rezki,
Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang,
open list:TORTURE-TEST MODULES, open list:READ-COPY UPDATE (RCU)
On Thu, Aug 21, 2025 at 09:41:15PM +0800, Qianfeng Rong wrote:
> Replace kzalloc() with kcalloc() in kernel/rcu. As noted in the kernel
> documentation [1], open-coded multiplication in allocator arguments is
> discouraged because it can lead to integer overflow.
>
> Use kcalloc() to gain built-in overflow protection, making memory
> allocation safer when calculating allocation size compared to explicit
> multiplication.
>
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments #1
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Queued for review and testing, thank you!
Thanx, Paul
> Qianfeng Rong (2):
> rcutorture: Use kcalloc() instead of kzalloc()
> refscale: Use kcalloc() instead of kzalloc()
>
> kernel/rcu/rcutorture.c | 4 ++--
> kernel/rcu/refscale.c | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-21 15:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 13:41 [PATCH 0/2] rcu: Use kcalloc() instead of kzalloc() Qianfeng Rong
2025-08-21 13:41 ` [PATCH 1/2] rcutorture: " Qianfeng Rong
2025-08-21 13:41 ` [PATCH 2/2] refscale: " Qianfeng Rong
2025-08-21 15:27 ` [PATCH 0/2] rcu: " Paul E. McKenney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).