Thread (9 messages) 9 messages, 2 authors, 2020-01-20

Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount

From: Viresh Kumar <viresh.kumar@linaro.org>
Date: 2020-01-20 06:01:38
Also in: linux-pm, lkml

On 20-01-20, 13:58, chenqiwu wrote:
On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote:
quoted
On 19-01-20, 15:09, qiwuchen55@gmail.com wrote:
quoted
From: chenqiwu <redacted>

brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy,
meanwhile, it also increments the kobject reference count to mark it busy.
However, a corresponding call of cpufreq_cpu_put() is ignored to decrement
the kobject reference count back, which may lead to a potential stuck risk
that the cpuhp thread deadly waits for dropping of kobject refcount when
cpufreq policy free.

For fixing this bug, cpufreq_get_policy() is referenced to do a proper
cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user.
If the policy return NULL, we just return 0 to hit the code path of
cpufreq_driver->get.

Signed-off-by: chenqiwu <redacted>
---
 drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
index 77b0e5d..ee0d404 100644
--- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
+++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
@@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv)
 
 static unsigned int brcm_avs_cpufreq_get(unsigned int cpu)
 {
-	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ?
cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(),
meanwhile fills a policy copy for the user. It equals to using
cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access
to the policy pointer. I think both methods are fine here.
What do you think?
cpufreq_get_policy() does an extra memcpy as well, which isn't required at all
in your case.

-- 
viresh

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help