* [PATCH] sched/topology: convert NUMA distance masks allocation to kcalloc()
@ 2026-06-05 18:24 William Theesfeld
2026-06-15 15:19 ` Valentin Schneider
0 siblings, 1 reply; 2+ messages in thread
From: William Theesfeld @ 2026-06-05 18:24 UTC (permalink / raw)
To: Ingo Molnar
Cc: Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
K Prateek Nayak, linux-kernel
sched_init_numa() builds the per-level NUMA distance masks via an
open-coded kzalloc(nr_node_ids * sizeof(void *), ...). Switch to
kcalloc(), which carries the same zero-on-allocation semantics and
adds the standard size_mul overflow check on the multiplication.
nr_node_ids is bounded by MAX_NUMNODES at compile time, so the
overflow check folds away in practice; the conversion is for
consistency with the kernel-wide pattern and to keep kernel/sched/
free of the open-coded form.
No functional change.
Signed-off-by: William Theesfeld <william@theesfeld.net>
---
kernel/sched/topology.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 5847b83d9..bb900ae22 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2083,7 +2083,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;
--
2.54.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] sched/topology: convert NUMA distance masks allocation to kcalloc()
2026-06-05 18:24 [PATCH] sched/topology: convert NUMA distance masks allocation to kcalloc() William Theesfeld
@ 2026-06-15 15:19 ` Valentin Schneider
0 siblings, 0 replies; 2+ messages in thread
From: Valentin Schneider @ 2026-06-15 15:19 UTC (permalink / raw)
To: William Theesfeld, Ingo Molnar
Cc: Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, K Prateek Nayak,
linux-kernel
On 05/06/26 14:24, William Theesfeld wrote:
> sched_init_numa() builds the per-level NUMA distance masks via an
> open-coded kzalloc(nr_node_ids * sizeof(void *), ...). Switch to
> kcalloc(), which carries the same zero-on-allocation semantics and
> adds the standard size_mul overflow check on the multiplication.
>
> nr_node_ids is bounded by MAX_NUMNODES at compile time, so the
> overflow check folds away in practice; the conversion is for
> consistency with the kernel-wide pattern and to keep kernel/sched/
> free of the open-coded form.
>
What about other simlar kzalloc() use just in that function, and at large
in the remainder of topology.c?
Coccinelle tells me there's a handful; surely that script can be improved
to automagically patch the code and DTRT.
---
virtual report
@kzalloc@
expression E1, E2;
position p;
@@
* kzalloc@p(E1 * E2, ...)
@script:python@
p << kzalloc.p;
@@
msg = "WARNING: kzalloc() with multiplication should be kcalloc()"
coccilib.report.print_report(p[0], msg)
---
$ /usr/bin/spatch -D report --no-show-diff --very-quiet --cocci-file ./scripts/coccinelle/api/kzalloc_to_kcalloc.cocci --no-includes --include-headers -I ./arch/x86/include -I ./arch/x86/include/generated -I ./include -I ./include -I ./arch/x86/include/uapi -I ./arch/x86/include/generated/uapi -I ./include/uapi -I ./include/generated/uapi --include ./include/linux/compiler-version.h --include ./include/linux/kconfig.h --dir kernel/sched
5 files match
kernel/sched/topology.c:2363:9-16: WARNING: kzalloc() with multiplication should be kcalloc()
kernel/sched/topology.c:2372:13-20: WARNING: kzalloc() with multiplication should be kcalloc()
kernel/sched/topology.c:2404:6-13: WARNING: kzalloc() with multiplication should be kcalloc()
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-15 15:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-05 18:24 [PATCH] sched/topology: convert NUMA distance masks allocation to kcalloc() William Theesfeld
2026-06-15 15:19 ` 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®