linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: rjw@rjwysocki.net, skannan@codeaurora.org
Cc: linaro-kernel@lists.linaro.org, cpufreq@vger.kernel.org,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	srivatsa.bhat@linux.vnet.ibm.com,
	Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH V2 2/3] cpufreq: Initialize policy before making it available for others to use
Date: Tue,  4 Mar 2014 11:44:00 +0800	[thread overview]
Message-ID: <99ab97f08241ac295eae898b48587fedda13f340.1393904428.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org>
In-Reply-To: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org>

Policy must be fully initialized before it is being made available for use by
others. Otherwise cpufreq_cpu_get() would be able to grab a half initialized
policy structure that might not have affected_cpus (for example) filled. And so
anybody accessing those fields will get the wrong value and hence the results
would be unpredictable.

So, in order to fix this lets do all the necessary initialization before we make
policy structure available via cpufreq_cpu_get(). With this we can guarantee
that any code accessing fields of policy would be stable enough, as policy would
be completely initialized by now.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
V1->V2:
- Improved commit logs

 drivers/cpufreq/cpufreq.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index fff2968..3c6f9a5 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1114,6 +1114,20 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
 		goto err_set_policy_cpu;
 	}
 
+	/* related cpus should atleast have policy->cpus */
+	cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);
+
+	/*
+	 * affected cpus must always be the one, which are online. We aren't
+	 * managing offline cpus here.
+	 */
+	cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
+
+	if (!frozen) {
+		policy->user_policy.min = policy->min;
+		policy->user_policy.max = policy->max;
+	}
+
 	write_lock_irqsave(&cpufreq_driver_lock, flags);
 	for_each_cpu(j, policy->cpus)
 		per_cpu(cpufreq_cpu_data, j) = policy;
@@ -1167,20 +1181,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
 		}
 	}
 
-	/* related cpus should atleast have policy->cpus */
-	cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);
-
-	/*
-	 * affected cpus must always be the one, which are online. We aren't
-	 * managing offline cpus here.
-	 */
-	cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
-
-	if (!frozen) {
-		policy->user_policy.min = policy->min;
-		policy->user_policy.max = policy->max;
-	}
-
 	blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
 				     CPUFREQ_START, policy);
 
-- 
1.7.12.rc2.18.g61b472e


  reply	other threads:[~2014-03-04  3:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04  3:43 [PATCH V2 1/3] cpufreq: move call to __find_governor() to cpufreq_init_policy() Viresh Kumar
2014-03-04  3:44 ` Viresh Kumar [this message]
2014-03-04  3:44 ` [PATCH V2 3/3] cpufreq: initialize governor for a new policy under policy->rwsem Viresh Kumar
2014-03-06  1:04   ` Rafael J. Wysocki
2014-03-06  1:06     ` Rafael J. Wysocki
2014-03-06  1:10       ` Saravana Kannan
2014-03-06  1:27         ` Rafael J. Wysocki
2014-03-06  2:24     ` Viresh Kumar
2014-03-06 12:34       ` Rafael J. Wysocki

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=99ab97f08241ac295eae898b48587fedda13f340.1393904428.git.viresh.kumar@linaro.org \
    --to=viresh.kumar@linaro.org \
    --cc=cpufreq@vger.kernel.org \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=skannan@codeaurora.org \
    --cc=srivatsa.bhat@linux.vnet.ibm.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).