Linux Power Management development
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Cc: Rafael Wysocki <rjw@rjwysocki.net>,
	linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org,
	ego@linux.vnet.ibm.com, paulus@samba.org,
	shilpa.bhat@linux.vnet.ibm.com, prarit@redhat.com,
	robert.schoene@tu-dresden.de, skannan@codeaurora.org
Subject: Re: [PATCH 2/3] cpufreq: governor: split cpufreq_governor_dbs()
Date: Thu, 4 Jun 2015 15:47:06 +0530	[thread overview]
Message-ID: <20150604101706.GB743@linux> (raw)
In-Reply-To: <5570229F.3080808@linux.vnet.ibm.com>

On 04-06-15, 15:34, Preeti U Murthy wrote:
> > +	if (dbs_data) {
> > +		WARN_ON(have_governor_per_policy());
> 
> Shouldn't this be outside this loop ? We warn here and allocate dbs_dta

Loop ? Its just an 'if' block :)

> freshly in the current code for the case where governor is per policy.

So what we are doing in the current code is equally disgusting. We
already have a pointer and we overwrite it.

> 
> > +		dbs_data->usage_count++;
> 
> Besides, in the case where a governor exists per policy, we will end up
> incrementing the usage_count to more than 1 under this condition, which
> does not make sense.

So, the only sane option here is to return an error immediately I
think.

diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index ed849a8777dd..57a39f8a92b7 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -247,7 +247,8 @@ static int cpufreq_governor_init(struct cpufreq_policy *policy,
 	int ret;
 
 	if (dbs_data) {
-		WARN_ON(have_governor_per_policy());
+		if (WARN_ON(have_governor_per_policy()))
+			return -EINVAL;
 		dbs_data->usage_count++;
 		policy->governor_data = dbs_data;
 		return 0;
@@ -276,24 +277,28 @@ static int cpufreq_governor_init(struct cpufreq_policy *policy,
 					latency * LATENCY_MULTIPLIER));
 
 	if (!have_governor_per_policy()) {
-		WARN_ON(cpufreq_get_global_kobject());
+		if (WARN_ON(cpufreq_get_global_kobject())) {
+			ret = -EINVAL;
+			goto cdata_exit;
+		}
 		cdata->gdbs_data = dbs_data;
 	}
 
 	ret = sysfs_create_group(get_governor_parent_kobj(policy),
 				 get_sysfs_attr(dbs_data));
 	if (ret)
-		goto cdata_exit;
+		goto put_kobj;
 
 	policy->governor_data = dbs_data;
 
 	return 0;
 
-cdata_exit:
+put_kobj:
 	if (!have_governor_per_policy()) {
 		cdata->gdbs_data = NULL;
 		cpufreq_put_global_kobject();
 	}
+cdata_exit:
 	cdata->exit(dbs_data, !policy->governor->initialized);
 free_dbs_data:
 	kfree(dbs_data);

-- 
viresh

  reply	other threads:[~2015-06-04 10:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-03 10:27 [PATCH 0/3] cpufreq: governor: Fix potential races Viresh Kumar
2015-06-03 10:27 ` [PATCH 1/3] cpufreq: governor: register notifier from cs_init() Viresh Kumar
2015-06-04  5:38   ` Preeti U Murthy
2015-06-04  6:02     ` Viresh Kumar
2015-06-04  7:33       ` Preeti U Murthy
2015-06-03 10:27 ` [PATCH 2/3] cpufreq: governor: split cpufreq_governor_dbs() Viresh Kumar
2015-06-04 10:04   ` Preeti U Murthy
2015-06-04 10:17     ` Viresh Kumar [this message]
2015-06-04 11:13   ` [PATCH V2 " Viresh Kumar
2015-06-05  2:51     ` Preeti U Murthy
2015-06-03 10:27 ` [PATCH 3/3] cpufreq: governor: Serialize governor callbacks Viresh Kumar
2015-06-04 10:47   ` Preeti U Murthy
2015-06-04  5:14 ` [PATCH 0/3] cpufreq: governor: Fix potential races Preeti U Murthy
2015-06-04  6:08   ` Preeti U Murthy
2015-06-04  6:11     ` Viresh Kumar
2015-06-04  6:36       ` Preeti U Murthy
2015-06-04  6:42         ` Viresh Kumar
2015-06-04  7:04           ` Preeti U Murthy
2015-06-04  7:13             ` Viresh Kumar
2015-06-04  7:27               ` Preeti U Murthy
2015-06-05  3:00   ` Viresh Kumar
2015-06-05  3:04     ` Preeti U Murthy
2015-06-05  4:05     ` Preeti U Murthy
2015-06-15 23:48 ` 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=20150604101706.GB743@linux \
    --to=viresh.kumar@linaro.org \
    --cc=ego@linux.vnet.ibm.com \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=prarit@redhat.com \
    --cc=preeti@linux.vnet.ibm.com \
    --cc=rjw@rjwysocki.net \
    --cc=robert.schoene@tu-dresden.de \
    --cc=shilpa.bhat@linux.vnet.ibm.com \
    --cc=skannan@codeaurora.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