* [PATCH v2] sched/topology: Convert kzalloc() to kcalloc() in topology.c
@ 2025-12-18 2:57 Fushuai Wang
2025-12-18 4:30 ` Madadi Vineeth Reddy
2026-01-05 16:18 ` Valentin Schneider
0 siblings, 2 replies; 3+ messages in thread
From: Fushuai Wang @ 2025-12-18 2:57 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
rostedt, bsegall, mgorman, vschneid
Cc: linux-kernel, wangfushuai, Fushuai Wang
The kzalloc() doesn't check for overflows in size multiplication,
so use kcalloc() instead.
Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
v1->v2: remove useless parenthesis
kernel/sched/topology.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index cf643a5ddedd..d228abe45c12 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2055,7 +2055,7 @@ void sched_init_numa(int offline_node)
sched_domains_numa_levels = 0;
- masks = kzalloc(sizeof(void *) * nr_levels, GFP_KERNEL);
+ masks = kcalloc(nr_levels, sizeof(void *), GFP_KERNEL);
if (!masks)
return;
@@ -2064,7 +2064,7 @@ void sched_init_numa(int offline_node)
* CPUs of nodes that are that many hops away from us.
*/
for (i = 0; i < nr_levels; i++) {
- masks[i] = kzalloc(nr_node_ids * sizeof(void *), GFP_KERNEL);
+ masks[i] = kcalloc(nr_node_ids, sizeof(void *), GFP_KERNEL);
if (!masks[i])
return;
@@ -2096,7 +2096,7 @@ void sched_init_numa(int offline_node)
/* Compute default topology size */
for (i = 0; sched_domain_topology[i].mask; i++);
- tl = kzalloc((i + nr_levels + 1) *
+ tl = kcalloc(i + nr_levels + 1,
sizeof(struct sched_domain_topology_level), GFP_KERNEL);
if (!tl)
return;
--
2.36.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] sched/topology: Convert kzalloc() to kcalloc() in topology.c
2025-12-18 2:57 [PATCH v2] sched/topology: Convert kzalloc() to kcalloc() in topology.c Fushuai Wang
@ 2025-12-18 4:30 ` Madadi Vineeth Reddy
2026-01-05 16:18 ` Valentin Schneider
1 sibling, 0 replies; 3+ messages in thread
From: Madadi Vineeth Reddy @ 2025-12-18 4:30 UTC (permalink / raw)
To: Fushuai Wang
Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
rostedt, bsegall, mgorman, vschneid, linux-kernel, wangfushuai,
Madadi Vineeth Reddy
Hi Fushuai,
On 18/12/25 08:27, Fushuai Wang wrote:
> The kzalloc() doesn't check for overflows in size multiplication,
> so use kcalloc() instead.
>
> Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
> ---
> v1->v2: remove useless parenthesis
>
> kernel/sched/topology.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index cf643a5ddedd..d228abe45c12 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -2055,7 +2055,7 @@ void sched_init_numa(int offline_node)
>
> sched_domains_numa_levels = 0;
>
> - masks = kzalloc(sizeof(void *) * nr_levels, GFP_KERNEL);
> + masks = kcalloc(nr_levels, sizeof(void *), GFP_KERNEL);
> if (!masks)
> return;
>
> @@ -2064,7 +2064,7 @@ void sched_init_numa(int offline_node)
> * CPUs of nodes that are that many hops away from us.
> */
> for (i = 0; i < nr_levels; i++) {
> - masks[i] = kzalloc(nr_node_ids * sizeof(void *), GFP_KERNEL);
> + masks[i] = kcalloc(nr_node_ids, sizeof(void *), GFP_KERNEL);
> if (!masks[i])
> return;
>
> @@ -2096,7 +2096,7 @@ void sched_init_numa(int offline_node)
> /* Compute default topology size */
> for (i = 0; sched_domain_topology[i].mask; i++);
>
> - tl = kzalloc((i + nr_levels + 1) *
> + tl = kcalloc(i + nr_levels + 1,
> sizeof(struct sched_domain_topology_level), GFP_KERNEL);
> if (!tl)
> return;
Practically, overflow seems highly unlikely here given the maximum values of
nr_levels and nr_node_ids.
However, since the code path is used only once during the boot initialization,
it shouldn't hurt to have this change.
Hence,
Reviewed-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Thanks,
Vineeth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] sched/topology: Convert kzalloc() to kcalloc() in topology.c
2025-12-18 2:57 [PATCH v2] sched/topology: Convert kzalloc() to kcalloc() in topology.c Fushuai Wang
2025-12-18 4:30 ` Madadi Vineeth Reddy
@ 2026-01-05 16:18 ` Valentin Schneider
1 sibling, 0 replies; 3+ messages in thread
From: Valentin Schneider @ 2026-01-05 16:18 UTC (permalink / raw)
To: Fushuai Wang, mingo, peterz, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman
Cc: linux-kernel, wangfushuai, Fushuai Wang
On 18/12/25 10:57, Fushuai Wang wrote:
> The kzalloc() doesn't check for overflows in size multiplication,
> so use kcalloc() instead.
>
> Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-05 16:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-18 2:57 [PATCH v2] sched/topology: Convert kzalloc() to kcalloc() in topology.c Fushuai Wang
2025-12-18 4:30 ` Madadi Vineeth Reddy
2026-01-05 16:18 ` Valentin Schneider
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®