linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Sudeep Holla <sudeep.holla@arm.com>
To: Gavin Shan <gshan@redhat.com>
Cc: mark.rutland@arm.com, lorenzo.pieralisi@arm.com,
	linux-arm-kernel@lists.infradead.org,
	Sudeep Holla <sudeep.holla@arm.com>
Subject: Re: [PATCH] drivers/firmware/psci: Fix memory leak in alloc_init_cpu_groups()
Date: Thu, 30 Jan 2020 11:02:39 +0000	[thread overview]
Message-ID: <20200130110239.GC48466@bogus> (raw)
In-Reply-To: <20200130034938.158504-1-gshan@redhat.com>

On Thu, Jan 30, 2020 at 02:49:38PM +1100, Gavin Shan wrote:
> The CPU mask (@tmp) should be free'd on failing to allocating the element
> of @cpu_groups[]. Otherwise, it leads to memory leakage because the CPU
> mask variable is allocated with CONFIG_CPUMASK_OFFSTACK.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>  drivers/firmware/psci/psci_checker.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/psci_checker.c
> index 6a445397771c..d1d6d1135fed 100644
> --- a/drivers/firmware/psci/psci_checker.c
> +++ b/drivers/firmware/psci/psci_checker.c
> @@ -167,6 +167,7 @@ static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups)
>  			topology_core_cpumask(cpumask_any(tmp));
>  
>  		if (!alloc_cpumask_var(&cpu_groups[num_groups], GFP_KERNEL)) {
> +			free_cpumask_var(tmp);

You may need also below diff, right ?

-->8

diff --git i/drivers/firmware/psci/psci_checker.c w/drivers/firmware/psci/psci_checker.c
index 6a445397771c..c5a5c76a9fda 100644
--- i/drivers/firmware/psci/psci_checker.c
+++ w/drivers/firmware/psci/psci_checker.c
@@ -157,8 +157,10 @@ static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups)

        cpu_groups = kcalloc(nb_available_cpus, sizeof(cpu_groups),
                             GFP_KERNEL);
-       if (!cpu_groups)
+       if (!cpu_groups) {
+               free_cpumask_var(tmp);
                return -ENOMEM;
+       }

        cpumask_copy(tmp, cpu_online_mask);


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      parent reply	other threads:[~2020-01-30 11:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30  3:49 [PATCH] drivers/firmware/psci: Fix memory leak in alloc_init_cpu_groups() Gavin Shan
2020-01-30  4:00 ` Gavin Shan
2020-01-30 11:05   ` Sudeep Holla
2020-01-30 21:41     ` Gavin Shan
2020-01-30 11:02 ` Sudeep Holla [this message]

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=20200130110239.GC48466@bogus \
    --to=sudeep.holla@arm.com \
    --cc=gshan@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.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;
as well as URLs for NNTP newsgroup(s).