[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250222-sched-kcalloc-v1-1-4dee15fd8241@ethancedwards.com>
Date: Sat, 22 Feb 2025 14:46:23 -0500
From: Ethan Carter Edwards <ethan@...ancedwards.com>
To: Markus Elfring <Markus.Elfring@....de>
Cc: Ingo Molnar <mingo@...hat.com>, Peter Zijlstra <peterz@...radead.org>,
Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Steven Rostedt <rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>,
Mel Gorman <mgorman@...e.de>, Valentin Schneider <vschneid@...hat.com>,
linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org,
Ethan Carter Edwards <ethan@...ancedwards.com>
Subject: [PATCH] sched/topology: replace kzalloc() with kcalloc() in
sched_init_numa()
We are trying to get rid of all multiplications from allocation
functions to prevent integer overflows[1]. Here the multiplication is
obviously safe, but using kcalloc() is more appropriate and improves
readability. This patch has no effect on runtime behavior.
Link: https://github.com/KSPP/linux/issues/162 [1]
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Signed-off-by: Ethan Carter Edwards <ethan@...ancedwards.com>
---
kernel/sched/topology.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index c49aea8c10254dec985bba47b18f61be954d23f6..b4539b29fb36f6b2f0c5ca310620ebda29755e5c 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -1918,7 +1918,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;
@@ -1927,7 +1927,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;
---
base-commit: 5cf80612d3f72c46ad53ef5042b4c609c393122f
change-id: 20250222-sched-kcalloc-1d5acea7249b
Best regards,
--
Ethan Carter Edwards <ethan@...ancedwards.com>
Powered by blists - more mailing lists