Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	Mario Limonciello <mario.limonciello@amd.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 1/4] cpufreq: Consolidate some code in cpufreq_online()
Date: Thu,  3 Dec 2026 14:30:23 -0500	[thread overview]
Message-ID: <20261203193010.628401-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120247-residency-drab-33a4@gregkh>

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

[ Upstream commit 387b51709db546033cf9a940860b6614a5cda5b6 ]

Notice that the policy->cpu update in cpufreq_policy_alloc() can be
moved to cpufreq_online() and then it can be carried out under the
policy rwsem, along with the clearing of policy->governor (unnecessary
in the "new policy" code branch, but also not harmful).  If this is
done, the bottom parts of the "if (policy)" branches become identical
and they can be collapsed and moved below the conditional.

Modify the code accordingly which makes it somewhat easier to follow.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
Link: https://patch.msgid.link/13741234.uLZWGnKmhe@rjwysocki.net
Stable-dep-of: c5bdb8757372 ("cpufreq: Skip inactive policies in cpufreq_driver_target()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/cpufreq/cpufreq.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 7c9e7d6556d38..6450bca6e3b74 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1323,7 +1323,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
 	init_waitqueue_head(&policy->transition_wait);
 	INIT_WORK(&policy->update, handle_update);
 
-	policy->cpu = cpu;
 	return policy;
 
 err_min_qos_notifier:
@@ -1411,17 +1410,18 @@ static int cpufreq_online(unsigned int cpu)
 
 		/* This is the only online CPU for the policy.  Start over. */
 		new_policy = false;
-		down_write(&policy->rwsem);
-		policy->cpu = cpu;
-		policy->governor = NULL;
 	} else {
 		new_policy = true;
 		policy = cpufreq_policy_alloc(cpu);
 		if (!policy)
 			return -ENOMEM;
-		down_write(&policy->rwsem);
 	}
 
+	down_write(&policy->rwsem);
+
+	policy->cpu = cpu;
+	policy->governor = NULL;
+
 	if (!new_policy && cpufreq_driver->online) {
 		/* Recover policy->cpus using related_cpus */
 		cpumask_copy(policy->cpus, policy->related_cpus);
-- 
2.53.0


  reply	other threads:[~2026-12-03 19:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:59 FAILED: patch "[PATCH] cpufreq: Skip inactive policies in cpufreq_driver_target()" failed to apply to 6.6-stable tree gregkh
2026-12-03 19:30 ` Sasha Levin [this message]
2026-12-03 19:30   ` [PATCH 6.6.y 2/4] cpufreq: Split cpufreq_online() Sasha Levin
2026-12-03 19:30   ` [PATCH 6.6.y 3/4] cpufreq: Add and use cpufreq policy locking guards Sasha Levin
2026-12-03 19:30   ` [PATCH 6.6.y 4/4] cpufreq: Skip inactive policies in cpufreq_driver_target() Sasha Levin

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=20261203193010.628401-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=viresh.kumar@linaro.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