public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Gavin Shan <gshan@redhat.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Will Deacon <will@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.19 13/13] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups()
Date: Tue, 14 Jul 2020 10:39:37 -0400	[thread overview]
Message-ID: <20200714143937.4035685-13-sashal@kernel.org> (raw)
In-Reply-To: <20200714143937.4035685-1-sashal@kernel.org>

From: Gavin Shan <gshan@redhat.com>

[ Upstream commit c377e67c6271954969384f9be1b1b71de13eba30 ]

The CPU mask (@tmp) should be released on failing to allocate
@cpu_groups or any of its elements. Otherwise, it leads to memory
leakage because the CPU mask variable is dynamically allocated
when CONFIG_CPUMASK_OFFSTACK is enabled.

Signed-off-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Link: https://lore.kernel.org/r/20200630075227.199624-1-gshan@redhat.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/firmware/psci_checker.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/psci_checker.c b/drivers/firmware/psci_checker.c
index cbd53cb1b2d47..9f1a913933d53 100644
--- a/drivers/firmware/psci_checker.c
+++ b/drivers/firmware/psci_checker.c
@@ -164,8 +164,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);
 
@@ -174,6 +176,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);
 			free_cpu_groups(num_groups, &cpu_groups);
 			return -ENOMEM;
 		}
-- 
2.25.1


      parent reply	other threads:[~2020-07-14 14:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 14:39 [PATCH AUTOSEL 4.19 01/13] gpio: arizona: handle pm_runtime_get_sync failure case Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 02/13] gpio: arizona: put pm_runtime in case of failure Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 03/13] pinctrl: amd: fix npins for uart0 in kerncz_groups Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 04/13] mac80211: allow rx of mesh eapol frames with default rx key Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 05/13] scsi: scsi_transport_spi: Fix function pointer check Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 06/13] xtensa: fix __sync_fetch_and_{and,or}_4 declarations Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 07/13] xtensa: update *pos in cpuinfo_op.next Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 08/13] drivers/net/wan/lapbether: Fixed the value of hard_header_len Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 09/13] ALSA: hda/hdmi: fix failures at PCM open on Intel ICL and later Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 10/13] net: usb: qmi_wwan: add support for Quectel EG95 LTE modem Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 11/13] net: sky2: initialize return of gm_phy_read Sasha Levin
2020-07-14 14:39 ` [PATCH AUTOSEL 4.19 12/13] drm/nouveau/i2c/g94-: increase NV_PMGR_DP_AUXCTL_TRANSACTREQ timeout Sasha Levin
2020-07-14 14:39 ` Sasha Levin [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=20200714143937.4035685-13-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=gshan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=will@kernel.org \
    /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