mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aaron Plattner <aplattner@nvidia.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Subject: Re: [PATCH] cpufreq: unlock when failing cpufreq_update_policy()
Date: Wed, 18 Jun 2014 07:39:37 -0700	[thread overview]
Message-ID: <53A1A4A9.4060301@nvidia.com> (raw)
In-Reply-To: <CAKohpo=2fpi7GivgNGE+DgD3xPdku3WzKKD8+Ziz4gQ4P6pMxQ@mail.gmail.com>

On 06/18/2014 12:40 AM, Viresh Kumar wrote:
> On 18 June 2014 05:42, Aaron Plattner <aplattner@nvidia.com> wrote:
>> Commit bd0fa9bb455d introduced a failure path to cpufreq_update_policy() if
>> cpufreq_driver->get(cpu) returns NULL.  However, it jumps to the 'no_policy'
>> label, which exits without unlocking any of the locks the function acquired
>> earlier.  This causes later calls into cpufreq to hang.
>>
>> Fix this by creating a new 'unlock' label and jumping to that instead.
>>
>> Fixes: bd0fa9bb455d ("cpufreq: Return error if ->get() failed in cpufreq_update_policy()")
>> Link: https://devtalk.nvidia.com/default/topic/751903/kernel-3-15-and-nv-drivers-337-340-failed-to-initialize-the-nvidia-kernel-module-gtx-550-ti-/
>> Cc: Viresh Kumar <viresh.kumar@linaro.org>
>> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>> Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
>> ---
>> I haven't reproduced this problem so I couldn't test it, but the bug and its
>> solution seem obvious enough.
>>
>>   drivers/cpufreq/cpufreq.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index aed2b0cb83dc..5b6d04f3b9ea 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -2264,7 +2264,7 @@ int cpufreq_update_policy(unsigned int cpu)
>>                  new_policy.cur = cpufreq_driver->get(cpu);
>>                  if (WARN_ON(!new_policy.cur)) {
>>                          ret = -EIO;
>> -                       goto no_policy;
>> +                       goto unlock;
>>                  }
>>
>>                  if (!policy->cur) {
>> @@ -2279,6 +2279,7 @@ int cpufreq_update_policy(unsigned int cpu)
>>
>>          ret = cpufreq_set_policy(policy, &new_policy);
>>
>> +unlock:
>>          up_write(&policy->rwsem);
>>
>>          cpufreq_cpu_put(policy);
>
> Hmm, yes we do have a problem here but the code became a bit ugly
> now.. Can you please consider this diff instead?
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index aed2b0c..6caced5 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2242,10 +2242,8 @@ int cpufreq_update_policy(unsigned int cpu)
>          struct cpufreq_policy new_policy;
>          int ret;
>
> -       if (!policy) {
> -               ret = -ENODEV;
> -               goto no_policy;
> -       }
> +       if (!policy)
> +               return = -ENODEV;

I assume you meant "return -ENODEV"?

>          down_write(&policy->rwsem);
>
> @@ -2279,10 +2277,10 @@ int cpufreq_update_policy(unsigned int cpu)
>
>          ret = cpufreq_set_policy(policy, &new_policy);
>
> +no_policy:

'no_policy' implied to me that policy was NULL, so this label should 
still be renamed to 'unlock'.  I'll send out a v2 that does this.

>          up_write(&policy->rwsem);
>
>          cpufreq_cpu_put(policy);
> -no_policy:
>          return ret;
>   }
>   EXPORT_SYMBOL(cpufreq_update_policy);
>

-- 
Aaron

  reply	other threads:[~2014-06-18 14:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-18  0:12 Aaron Plattner
2014-06-18  7:40 ` Viresh Kumar
2014-06-18 14:39   ` Aaron Plattner [this message]
2014-06-18 14:41     ` Viresh Kumar
2014-06-18 18:27 ` [PATCH v2] " Aaron Plattner
2014-06-18 23:57   ` 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=53A1A4A9.4060301@nvidia.com \
    --to=aplattner@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.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

Powered by JetHome