From: Viresh Kumar <viresh.kumar@linaro.org>
To: Rafael Wysocki <rjw@rjwysocki.net>
Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org,
sboyd@codeaurora.org, prarit@redhat.com, skannan@codeaurora.org,
Srivatsa Bhat <srivatsa@mit.edu>,
Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH V7 3/6] cpufreq: Initialize policy->kobj while allocating policy
Date: Mon, 8 Jun 2015 18:25:29 +0530 [thread overview]
Message-ID: <ccce7f611de7fcd4fc130f99aea7657c4d753e92.1433767914.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1433767914.git.viresh.kumar@linaro.org>
In-Reply-To: <cover.1433767914.git.viresh.kumar@linaro.org>
policy->kobj is required to be initialized once in the lifetime of a
policy. Currently we are initializing it from __cpufreq_add_dev() and
that doesn't look to be the best place for doing so as we have to do
this on special cases (like: !recover_policy).
We can initialize it from a more obvious place cpufreq_policy_alloc()
and that will make code look cleaner, specially the error handling part.
The error handling part of __cpufreq_add_dev() was doing almost the same
thing while recover_policy is true or false. Fix that as well by always
calling cpufreq_policy_put_kobj() with an additional parameter to skip
notification part of it.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq.c | 46 +++++++++++++++++++++-------------------------
1 file changed, 21 insertions(+), 25 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 663a934259a4..d890804d561f 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1131,9 +1131,10 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
return policy;
}
-static struct cpufreq_policy *cpufreq_policy_alloc(int cpu)
+static struct cpufreq_policy *cpufreq_policy_alloc(struct device *dev)
{
struct cpufreq_policy *policy;
+ int ret;
policy = kzalloc(sizeof(*policy), GFP_KERNEL);
if (!policy)
@@ -1145,6 +1146,13 @@ static struct cpufreq_policy *cpufreq_policy_alloc(int cpu)
if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
goto err_free_cpumask;
+ ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, &dev->kobj,
+ "cpufreq");
+ if (ret) {
+ pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret);
+ goto err_free_rcpumask;
+ }
+
INIT_LIST_HEAD(&policy->policy_list);
init_rwsem(&policy->rwsem);
spin_lock_init(&policy->transition_lock);
@@ -1152,13 +1160,15 @@ static struct cpufreq_policy *cpufreq_policy_alloc(int cpu)
init_completion(&policy->kobj_unregister);
INIT_WORK(&policy->update, handle_update);
- policy->cpu = cpu;
+ policy->cpu = dev->id;
/* Set this once on allocation */
- policy->kobj_cpu = cpu;
+ policy->kobj_cpu = dev->id;
return policy;
+err_free_rcpumask:
+ free_cpumask_var(policy->related_cpus);
err_free_cpumask:
free_cpumask_var(policy->cpus);
err_free_policy:
@@ -1167,13 +1177,14 @@ static struct cpufreq_policy *cpufreq_policy_alloc(int cpu)
return NULL;
}
-static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy)
+static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy, bool notify)
{
struct kobject *kobj;
struct completion *cmp;
- blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
- CPUFREQ_REMOVE_POLICY, policy);
+ if (notify)
+ blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
+ CPUFREQ_REMOVE_POLICY, policy);
down_write(&policy->rwsem);
cpufreq_remove_dev_symlink(policy);
@@ -1273,7 +1284,7 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
policy = recover_policy ? cpufreq_policy_restore(cpu) : NULL;
if (!policy) {
recover_policy = false;
- policy = cpufreq_policy_alloc(cpu);
+ policy = cpufreq_policy_alloc(dev);
if (!policy)
goto nomem_out;
}
@@ -1313,15 +1324,6 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
policy->user_policy.min = policy->min;
policy->user_policy.max = policy->max;
- /* prepare interface data */
- ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
- &dev->kobj, "cpufreq");
- if (ret) {
- pr_err("%s: failed to init policy->kobj: %d\n",
- __func__, ret);
- goto err_init_policy_kobj;
- }
-
write_lock_irqsave(&cpufreq_driver_lock, flags);
for_each_cpu(j, policy->related_cpus)
per_cpu(cpufreq_cpu_data, j) = policy;
@@ -1413,18 +1415,12 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
err_out_unregister:
err_get_freq:
- if (!recover_policy) {
- kobject_put(&policy->kobj);
- wait_for_completion(&policy->kobj_unregister);
- }
-err_init_policy_kobj:
up_write(&policy->rwsem);
if (cpufreq_driver->exit)
cpufreq_driver->exit(policy);
err_set_policy_cpu:
- if (recover_policy)
- cpufreq_policy_put_kobj(policy);
+ cpufreq_policy_put_kobj(policy, recover_policy);
cpufreq_policy_free(policy);
nomem_out:
@@ -1520,7 +1516,7 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
/* Free the policy kobjects only if the driver is getting removed. */
if (sif)
- cpufreq_policy_put_kobj(policy);
+ cpufreq_policy_put_kobj(policy, true);
/*
* Perform the ->exit() even during light-weight tear-down,
@@ -1570,7 +1566,7 @@ static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
return 0;
}
- cpufreq_policy_put_kobj(policy);
+ cpufreq_policy_put_kobj(policy, true);
cpufreq_policy_free(policy);
return 0;
}
--
2.4.0
next prev parent reply other threads:[~2015-06-08 12:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-08 12:55 [PATCH V7 0/6] cpufreq: Don't loose cpufreq history on CPU hotplug Viresh Kumar
2015-06-08 12:55 ` [PATCH V7 1/6] cpufreq: Don't allow updating inactive policies from sysfs Viresh Kumar
2015-06-08 23:19 ` Rafael J. Wysocki
2015-06-09 2:46 ` Viresh Kumar
2015-06-09 21:50 ` Saravana Kannan
2015-06-08 12:55 ` [PATCH V7 2/6] cpufreq: Stop migrating sysfs files on hotplug Viresh Kumar
2015-06-08 23:23 ` Rafael J. Wysocki
2015-06-09 2:50 ` Viresh Kumar
2015-06-10 0:20 ` Saravana Kannan
2015-06-10 2:19 ` Viresh Kumar
2015-06-10 23:29 ` Rafael J. Wysocki
2015-06-08 12:55 ` Viresh Kumar [this message]
2015-06-08 12:55 ` [PATCH V7 4/6] cpufreq: Call cpufreq_policy_put_kobj() from cpufreq_policy_free() Viresh Kumar
2015-06-08 12:55 ` [PATCH V7 5/6] cpufreq: Restart governor as soon as possible Viresh Kumar
2015-06-08 23:27 ` Rafael J. Wysocki
2015-06-09 3:09 ` Viresh Kumar
2015-06-08 12:55 ` [PATCH V7 6/6] cpufreq: Remove cpufreq_update_policy() Viresh Kumar
2015-06-08 23:17 ` [PATCH V7 0/6] cpufreq: Don't loose cpufreq history on CPU hotplug 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=ccce7f611de7fcd4fc130f99aea7657c4d753e92.1433767914.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-pm@vger.kernel.org \
--cc=prarit@redhat.com \
--cc=rjw@rjwysocki.net \
--cc=sboyd@codeaurora.org \
--cc=skannan@codeaurora.org \
--cc=srivatsa@mit.edu \
/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).