From: Xiongfeng Wang <wangxiongfeng2@huawei.com>
To: <rafael@kernel.org>, <viresh.kumar@linaro.org>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<guohanjun@huawei.com>, <wangxiongfeng2@huawei.com>
Subject: [PATCH] cpufreq: Fix get_cpu_device() failed in add_cpu_dev_symlink()
Date: Mon, 29 Nov 2021 16:02:48 +0800 [thread overview]
Message-ID: <20211129080248.46240-1-wangxiongfeng2@huawei.com> (raw)
When I hot added a CPU, I found 'cpufreq' directory is not created below
/sys/devices/system/cpu/cpuX/. It is because get_cpu_device() failed in
add_cpu_dev_symlink().
cpufreq_add_dev() is the .add_dev callback of a CPU subsys interface. It
will be called when the CPU device registered into the system. The stack
is as follows.
register_cpu()
->device_register()
->device_add()
->bus_probe_device()
->cpufreq_add_dev()
But only after the CPU device has been registered, we can get the CPU
device by get_cpu_device(), otherwise it will return NULL. Since we
already have the CPU device in cpufreq_add_dev(), pass it to
add_cpu_dev_symlink(). I noticed that the 'kobj' of the cpu device has
been added into the system before cpufreq_add_dev().
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
drivers/cpufreq/cpufreq.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index e338d2f010fe..22aa2793e4d2 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1004,10 +1004,9 @@ static struct kobj_type ktype_cpufreq = {
.release = cpufreq_sysfs_release,
};
-static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu)
+static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu,
+ struct device *dev)
{
- struct device *dev = get_cpu_device(cpu);
-
if (unlikely(!dev))
return;
@@ -1391,7 +1390,7 @@ static int cpufreq_online(unsigned int cpu)
if (new_policy) {
for_each_cpu(j, policy->related_cpus) {
per_cpu(cpufreq_cpu_data, j) = policy;
- add_cpu_dev_symlink(policy, j);
+ add_cpu_dev_symlink(policy, j, get_cpu_device(j));
}
policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req),
@@ -1565,7 +1564,7 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
/* Create sysfs link on CPU registration */
policy = per_cpu(cpufreq_cpu_data, cpu);
if (policy)
- add_cpu_dev_symlink(policy, cpu);
+ add_cpu_dev_symlink(policy, cpu, dev);
return 0;
}
--
2.20.1
next reply other threads:[~2021-11-29 7:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-29 8:02 Xiongfeng Wang [this message]
2021-11-29 9:10 ` [PATCH] cpufreq: Fix get_cpu_device() failed in add_cpu_dev_symlink() Viresh Kumar
2021-11-30 11:42 ` Rafael J. Wysocki
2021-12-01 1:29 ` Xiongfeng Wang
2021-12-01 7:23 ` Viresh Kumar
2021-12-01 18:52 ` 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=20211129080248.46240-1-wangxiongfeng2@huawei.com \
--to=wangxiongfeng2@huawei.com \
--cc=guohanjun@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).