@@ -967,6 +967,7 @@ static struct attribute *cpufreq_attrs[] = {
967967 & cpuinfo_min_freq .attr ,
968968 & cpuinfo_max_freq .attr ,
969969 & cpuinfo_transition_latency .attr ,
970+ & scaling_cur_freq .attr ,
970971 & scaling_min_freq .attr ,
971972 & scaling_max_freq .attr ,
972973 & affected_cpus .attr ,
@@ -1095,10 +1096,6 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
10951096 return ret ;
10961097 }
10971098
1098- ret = sysfs_create_file (& policy -> kobj , & scaling_cur_freq .attr );
1099- if (ret )
1100- return ret ;
1101-
11021099 if (cpufreq_driver -> bios_limit ) {
11031100 ret = sysfs_create_file (& policy -> kobj , & bios_limit .attr );
11041101 if (ret )
@@ -1284,6 +1281,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
12841281 goto err_free_real_cpus ;
12851282 }
12861283
1284+ init_rwsem (& policy -> rwsem );
1285+
12871286 freq_constraints_init (& policy -> constraints );
12881287
12891288 policy -> nb_min .notifier_call = cpufreq_notifier_min ;
@@ -1306,7 +1305,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
13061305 }
13071306
13081307 INIT_LIST_HEAD (& policy -> policy_list );
1309- init_rwsem (& policy -> rwsem );
13101308 spin_lock_init (& policy -> transition_lock );
13111309 init_waitqueue_head (& policy -> transition_wait );
13121310 INIT_WORK (& policy -> update , handle_update );
@@ -1694,14 +1692,13 @@ static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy)
16941692 return ;
16951693 }
16961694
1697- if (has_target ())
1695+ if (has_target ()) {
16981696 strscpy (policy -> last_governor , policy -> governor -> name ,
16991697 CPUFREQ_NAME_LEN );
1700- else
1701- policy -> last_policy = policy -> policy ;
1702-
1703- if (has_target ())
17041698 cpufreq_exit_governor (policy );
1699+ } else {
1700+ policy -> last_policy = policy -> policy ;
1701+ }
17051702
17061703 /*
17071704 * Perform the ->offline() during light-weight tear-down, as
@@ -1803,6 +1800,9 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b
18031800{
18041801 unsigned int new_freq ;
18051802
1803+ if (!cpufreq_driver -> get )
1804+ return 0 ;
1805+
18061806 new_freq = cpufreq_driver -> get (policy -> cpu );
18071807 if (!new_freq )
18081808 return 0 ;
@@ -1925,10 +1925,7 @@ unsigned int cpufreq_get(unsigned int cpu)
19251925
19261926 guard (cpufreq_policy_read )(policy );
19271927
1928- if (cpufreq_driver -> get )
1929- return __cpufreq_get (policy );
1930-
1931- return 0 ;
1928+ return __cpufreq_get (policy );
19321929}
19331930EXPORT_SYMBOL (cpufreq_get );
19341931
@@ -2482,8 +2479,7 @@ int cpufreq_start_governor(struct cpufreq_policy *policy)
24822479
24832480 pr_debug ("%s: for CPU %u\n" , __func__ , policy -> cpu );
24842481
2485- if (cpufreq_driver -> get )
2486- cpufreq_verify_current_freq (policy , false);
2482+ cpufreq_verify_current_freq (policy , false);
24872483
24882484 if (policy -> governor -> start ) {
24892485 ret = policy -> governor -> start (policy );
@@ -2715,10 +2711,12 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
27152711 pr_debug ("starting governor %s failed\n" , policy -> governor -> name );
27162712 if (old_gov ) {
27172713 policy -> governor = old_gov ;
2718- if (cpufreq_init_governor (policy ))
2714+ if (cpufreq_init_governor (policy )) {
2715+ policy -> governor = NULL ;
2716+ } else if (cpufreq_start_governor (policy )) {
2717+ cpufreq_exit_governor (policy );
27192718 policy -> governor = NULL ;
2720- else
2721- cpufreq_start_governor (policy );
2719+ }
27222720 }
27232721
27242722 return ret ;
@@ -2944,15 +2942,6 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
29442942 cpufreq_driver = driver_data ;
29452943 write_unlock_irqrestore (& cpufreq_driver_lock , flags );
29462944
2947- /*
2948- * Mark support for the scheduler's frequency invariance engine for
2949- * drivers that implement target(), target_index() or fast_switch().
2950- */
2951- if (!cpufreq_driver -> setpolicy ) {
2952- static_branch_enable_cpuslocked (& cpufreq_freq_invariance );
2953- pr_debug ("supports frequency invariance" );
2954- }
2955-
29562945 if (driver_data -> setpolicy )
29572946 driver_data -> flags |= CPUFREQ_CONST_LOOPS ;
29582947
@@ -2983,6 +2972,15 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
29832972 hp_online = ret ;
29842973 ret = 0 ;
29852974
2975+ /*
2976+ * Mark support for the scheduler's frequency invariance engine for
2977+ * drivers that implement target(), target_index() or fast_switch().
2978+ */
2979+ if (!cpufreq_driver -> setpolicy ) {
2980+ static_branch_enable_cpuslocked (& cpufreq_freq_invariance );
2981+ pr_debug ("supports frequency invariance" );
2982+ }
2983+
29862984 pr_debug ("driver %s up and running\n" , driver_data -> name );
29872985 goto out ;
29882986
0 commit comments