From: "Jon Medhurst (Tixy)" <tixy@linaro.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Rafael Wysocki <rjw@rjwysocki.net>,
linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] cpufreq: Properly handle errors from cpufreq_init_policy()
Date: Wed, 08 Jul 2015 12:17:56 +0100 [thread overview]
Message-ID: <1436354276.2844.20.camel@linaro.org> (raw)
In-Reply-To: <043703bd1914d52340653c3cc31207e505df6139.1436348436.git.viresh.kumar@linaro.org>
On Wed, 2015-07-08 at 15:12 +0530, Viresh Kumar wrote:
> cpufreq_init_policy() can fail, and we don't do anything except a call
> to ->exit() on that. The policy should be freed if this happens.
>
> Lets do it properly.
>
> Reported-by: "Jon Medhurst (Tixy)" <tixy@linaro.org>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
I tried these patches without the earlier "cpufreq: Initialize the
governor again while restoring policy" patch.
The result is that the error when bringing a cpu online is with flagged
up with a kernel message:
cpufreq: cpufreq_add_dev: Failed to initialize policy for cpu: 1 (-16)
and afterwards, the sysfs entries that I was poking and causing the
crash aren't present. So looks like this patch has done what we want,
and cleaned things up after an error. So...
Tested-by: Jon Medhurst <tixy@linaro.org>
Thanks for the prompt fix.
> drivers/cpufreq/cpufreq.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index b7aac8eec525..006299214d2e 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1051,11 +1051,10 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy,
> return cpufreq_add_dev_symlink(policy);
> }
>
> -static void cpufreq_init_policy(struct cpufreq_policy *policy)
> +static int cpufreq_init_policy(struct cpufreq_policy *policy)
> {
> struct cpufreq_governor *gov = NULL;
> struct cpufreq_policy new_policy;
> - int ret = 0;
>
> memcpy(&new_policy, policy, sizeof(*policy));
>
> @@ -1074,12 +1073,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)
> cpufreq_parse_governor(gov->name, &new_policy.policy, NULL);
>
> /* set default policy */
> - ret = cpufreq_set_policy(policy, &new_policy);
> - if (ret) {
> - pr_debug("setting policy failed\n");
> - if (cpufreq_driver->exit)
> - cpufreq_driver->exit(policy);
> - }
> + return cpufreq_set_policy(policy, &new_policy);
> }
>
> static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
> @@ -1376,7 +1370,12 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
> write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> }
>
> - cpufreq_init_policy(policy);
> + ret = cpufreq_init_policy(policy);
> + if (ret) {
> + pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n",
> + __func__, cpu, ret);
> + goto out_remove_policy_notify;
> + }
>
> if (!recover_policy) {
> policy->user_policy.policy = policy->policy;
> @@ -1396,6 +1395,9 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
>
> return 0;
>
> +out_remove_policy_notify:
> + /* cpufreq_policy_free() will notify based on this */
> + recover_policy = true;
> out_exit_policy:
> up_write(&policy->rwsem);
>
next prev parent reply other threads:[~2015-07-08 11:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-08 9:42 [PATCH 1/2] cpufreq: cpufreq_add_dev: name goto labels based on what they do Viresh Kumar
2015-07-08 9:42 ` Viresh Kumar
2015-07-08 9:42 ` [PATCH 2/2] cpufreq: Properly handle errors from cpufreq_init_policy() Viresh Kumar
2015-07-08 9:42 ` Viresh Kumar
2015-07-08 11:17 ` Jon Medhurst (Tixy) [this message]
2015-07-08 11:20 ` Viresh Kumar
2015-07-16 0:32 ` Rafael J. Wysocki
2015-07-16 9:16 ` Jon Medhurst (Tixy)
2015-07-16 23:07 ` 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=1436354276.2844.20.camel@linaro.org \
--to=tixy@linaro.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.