Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: Sudeep Holla <sudeep.holla@kernel.org>
To: driver-core@lists.linux.dev
Cc: Sudeep Holla <sudeep.holla@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v3 4/4] arch_topology: Free raw_capacity when topology parsing fails
Date: Mon,  9 Nov 2026 17:31:25 +0000	[thread overview]
Message-ID: <20261109173125.1734847-5-sudeep.holla@kernel.org> (raw)
In-Reply-To: <20261109173125.1734847-1-sudeep.holla@kernel.org>

When parsing /cpus/cpu-map fails in parse_dt_topology(),
init_cpu_topology() calls reset_cpu_topology() without calling
free_raw_capacity().

topology_parse_cpu_capacity() allocates raw_capacity on the first CPU
node with a capacity-dmips-mhz property. If a subsequent core, cluster
or socket fails to parse in parse_socket(), or if a possible CPU is
missing from cpu-map, raw_capacity is left allocated and partially
populated.

With CONFIG_CPU_FREQ=y, free_raw_capacity() is not registered as an
initcall. If cpufreq policies are registered for all possible CPUs,
init_cpu_capacity_callback() sees the non-NULL raw_capacity pointer and
runs topology_normalize_cpu_scale() on the incomplete array, leaving
unparsed CPUs with a capacity scale of 0; otherwise, raw_capacity is
leaked.

Free raw_capacity when init_cpu_topology() resets the topology on
parsing failure to discard the partial capacity data and avoid leaking
memory or setting unparsed CPUs to capacity 0.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-1a2a8094-971d-40cb-b0cf-2e6d9f26c549
Fixes: 60c1b220d8bc ("cpu-topology: Move cpu topology code to common code.")
Signed-off-by: Sudeep Holla <sudeep.holla@kernel.org>
---
 drivers/base/arch_topology.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index c439fc91270d..7783c0c517eb 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -954,6 +954,7 @@ void __init init_cpu_topology(void)
 		 * arch-specific early cache level detection a chance to run.
 		 */
 		reset_cpu_topology();
+		free_raw_capacity();
 		cpu_smt_set_num_threads(1, 1);
 	}
 
-- 
2.43.0


      parent reply	other threads:[~2026-11-09 17:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 17:31 [PATCH v3 0/4] arch_topology: Bunch of error patch related fixes Sudeep Holla
2026-11-09 17:31 ` [PATCH v3 1/4] arch_topology: Reset SMT state when socket parsing fails Sudeep Holla
2026-11-09 17:31 ` [PATCH v3 2/4] arch_topology: Free ACPI SMT entries on lookup failure Sudeep Holla
2026-11-09 17:31 ` [PATCH v3 3/4] arch_topology: Reset SMT state when topology is unavailable Sudeep Holla
2026-11-09 17:31 ` 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=20261109173125.1734847-5-sudeep.holla@kernel.org \
    --to=sudeep.holla@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=sashiko-bot@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