From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Richard Cochran <rcochran@linutronix.de>
Cc: linux-kernel@vger.kernel.org, rt@linutronix.de,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Viresh Kumar <viresh.kumar@linaro.org>,
Linux PM list <linux-pm@vger.kernel.org>
Subject: Re: [PATCH] cpufreq: Make cpufreq_quick_get() safe to call.
Date: Thu, 10 Mar 2016 23:20:47 +0100 [thread overview]
Message-ID: <3267506.5YnhcYthBi@vostro.rjw.lan> (raw)
In-Reply-To: <1457622636-10028-1-git-send-email-rcochran@linutronix.de>
On Thursday, March 10, 2016 04:10:36 PM Richard Cochran wrote:
> The function, cpufreq_quick_get, accesses the global 'cpufreq_driver' and
> its fields without taking the associated lock, cpufreq_driver_lock.
>
> Without the locking, nothing guarantees that 'cpufreq_driver' remains
> consistent during the call. This patch fixes the issue by taking the lock
> before accessing the data structure.
>
> Cc: Dirk Brandewie <dirk.brandewie@gmail.com>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Signed-off-by: Richard Cochran <rcochran@linutronix.de>
Can you please CC PM-related patches to linux-pm@vger.kernel.org? They
are much easier to handle for me then.
> ---
> drivers/cpufreq/cpufreq.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index e979ec7..ce02b2b 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1457,9 +1457,17 @@ unsigned int cpufreq_quick_get(unsigned int cpu)
> {
> struct cpufreq_policy *policy;
> unsigned int ret_freq = 0;
> + unsigned long flags;
> +
> + read_lock_irqsave(&cpufreq_driver_lock, flags);
>
> if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
> - return cpufreq_driver->get(cpu);
> + ret_freq = cpufreq_driver->get(cpu);
> +
> + read_unlock_irqrestore(&cpufreq_driver_lock, flags);
> +
> + if (ret_freq)
> + return ret_freq;
>
> policy = cpufreq_cpu_get(cpu);
> if (policy) {
>
I would prefer something like this:
read_lock_irqsave(&cpufreq_driver_lock, flags);
if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) {
unsigned int ret_freq = cpufreq_driver->get(cpu);
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
return ret_freq;
}
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
Thanks,
Rafael
next prev parent reply other threads:[~2016-03-10 22:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-10 15:10 Richard Cochran
2016-03-10 22:20 ` Rafael J. Wysocki [this message]
2016-03-11 2:23 ` Rafael J. Wysocki
2016-03-11 8:43 ` [PATCH v2] " Richard Cochran
2016-03-11 23:52 ` Viresh Kumar
2016-03-18 23: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=3267506.5YnhcYthBi@vostro.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=rcochran@linutronix.de \
--cc=rt@linutronix.de \
--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
all inboxes | Powered by JetHome®