Skip to content

Commit 2c1b5a8

Browse files
fenghusthurafaeljw
authored andcommitted
cpufreq: Fix get_cpu_device() failure in add_cpu_dev_symlink()
When I hot added a CPU, I found 'cpufreq' directory was 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 call chain 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(). Fixes: 2f0ba79 ("cpufreq: Fix creation of symbolic links to policy directories") Signed-off-by: Xiongfeng Wang <[email protected]> Acked-by: Viresh Kumar <[email protected]> Cc: All applicable <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent d58071a commit 2c1b5a8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,10 +1004,9 @@ static struct kobj_type ktype_cpufreq = {
10041004
.release = cpufreq_sysfs_release,
10051005
};
10061006

1007-
static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu)
1007+
static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu,
1008+
struct device *dev)
10081009
{
1009-
struct device *dev = get_cpu_device(cpu);
1010-
10111010
if (unlikely(!dev))
10121011
return;
10131012

@@ -1391,7 +1390,7 @@ static int cpufreq_online(unsigned int cpu)
13911390
if (new_policy) {
13921391
for_each_cpu(j, policy->related_cpus) {
13931392
per_cpu(cpufreq_cpu_data, j) = policy;
1394-
add_cpu_dev_symlink(policy, j);
1393+
add_cpu_dev_symlink(policy, j, get_cpu_device(j));
13951394
}
13961395

13971396
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)
15651564
/* Create sysfs link on CPU registration */
15661565
policy = per_cpu(cpufreq_cpu_data, cpu);
15671566
if (policy)
1568-
add_cpu_dev_symlink(policy, cpu);
1567+
add_cpu_dev_symlink(policy, cpu, dev);
15691568

15701569
return 0;
15711570
}

0 commit comments

Comments
 (0)