mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
To: Fushuai Wang <fushuai.wang@linux.dev>
Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	vschneid@redhat.com, linux-kernel@vger.kernel.org,
	wangfushuai@baidu.com,
	Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Subject: Re: [PATCH v2] sched/topology: Convert kzalloc() to kcalloc() in topology.c
Date: Thu, 18 Dec 2025 10:00:51 +0530	[thread overview]
Message-ID: <a65ca1f7-dcb8-46f7-9b55-7e7fbaaa4afe@linux.ibm.com> (raw)
In-Reply-To: <20251218025707.80581-1-fushuai.wang@linux.dev>

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

  reply	other threads:[~2025-12-18  4:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18  2:57 Fushuai Wang
2025-12-18  4:30 ` Madadi Vineeth Reddy [this message]
2026-01-05 16:18 ` Valentin Schneider

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=a65ca1f7-dcb8-46f7-9b55-7e7fbaaa4afe@linux.ibm.com \
    --to=vineethr@linux.ibm.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=fushuai.wang@linux.dev \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=wangfushuai@baidu.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®