From: Schspa Shi <schspa@gmail.com>
To: rafael@kernel.org, viresh.kumar@linaro.org, dan.carpenter@oracle.com
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, schspa@gmail.com
Subject: [PATCH] cpufreq: fix double unlock when cpufreq online
Date: Sat, 7 May 2022 01:00:35 +0800 [thread overview]
Message-ID: <20220506170035.32115-1-schspa@gmail.com> (raw)
In-Reply-To: <20220506072146.GD4031@kadam>
The patch f346e96267cd: ("cpufreq: Fix possible race in cpufreq online
error path") expand the critical region. But policy->rwsem is not held when
calling cpufreq_driver->online and cpufreq_driver->init calls, which lead to bad
unlock.
And it's well to hold this lock when calling cpufreq_driver->online, which
provide more protects without bad influence.
Fixes: f346e96267cd: ("cpufreq: Fix possible race in cpufreq online error path")
Link: https://lore.kernel.org/all/YnKZCGaig+EXSowf@kili/
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Schspa Shi <schspa@gmail.com>
---
drivers/cpufreq/cpufreq.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 0d58b0f8f3af..43dfaa8124e2 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1337,12 +1337,12 @@ static int cpufreq_online(unsigned int cpu)
down_write(&policy->rwsem);
policy->cpu = cpu;
policy->governor = NULL;
- up_write(&policy->rwsem);
} else {
new_policy = true;
policy = cpufreq_policy_alloc(cpu);
if (!policy)
return -ENOMEM;
+ down_write(&policy->rwsem);
}
if (!new_policy && cpufreq_driver->online) {
@@ -1382,7 +1382,6 @@ static int cpufreq_online(unsigned int cpu)
cpumask_copy(policy->related_cpus, policy->cpus);
}
- down_write(&policy->rwsem);
/*
* affected cpus must always be the one, which are online. We aren't
* managing offline cpus here.
@@ -1542,9 +1541,9 @@ static int cpufreq_online(unsigned int cpu)
cpufreq_driver->exit(policy);
cpumask_clear(policy->cpus);
- up_write(&policy->rwsem);
out_free_policy:
+ up_write(&policy->rwsem);
cpufreq_policy_free(policy);
return ret;
}
--
2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2022-05-06 17:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-04 15:17 [bug report] cpufreq: Fix possible race in cpufreq online error path Dan Carpenter
2022-05-06 6:43 ` Schspa Shi
2022-05-06 7:21 ` Dan Carpenter
2022-05-06 17:00 ` Schspa Shi [this message]
2022-05-09 4:00 ` [PATCH] cpufreq: fix double unlock when cpufreq online Viresh Kumar
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=20220506170035.32115-1-schspa@gmail.com \
--to=schspa@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--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.