@@ -621,6 +621,24 @@ static struct cpufreq_governor *find_governor(const char *str_governor)
621
621
return NULL ;
622
622
}
623
623
624
+ static struct cpufreq_governor * get_governor (const char * str_governor )
625
+ {
626
+ struct cpufreq_governor * t ;
627
+
628
+ mutex_lock (& cpufreq_governor_mutex );
629
+ t = find_governor (str_governor );
630
+ if (!t )
631
+ goto unlock ;
632
+
633
+ if (!try_module_get (t -> owner ))
634
+ t = NULL ;
635
+
636
+ unlock :
637
+ mutex_unlock (& cpufreq_governor_mutex );
638
+
639
+ return t ;
640
+ }
641
+
624
642
static unsigned int cpufreq_parse_policy (char * str_governor )
625
643
{
626
644
if (!strncasecmp (str_governor , "performance" , CPUFREQ_NAME_LEN ))
@@ -640,28 +658,14 @@ static struct cpufreq_governor *cpufreq_parse_governor(char *str_governor)
640
658
{
641
659
struct cpufreq_governor * t ;
642
660
643
- mutex_lock (& cpufreq_governor_mutex );
644
-
645
- t = find_governor (str_governor );
646
- if (!t ) {
647
- int ret ;
648
-
649
- mutex_unlock (& cpufreq_governor_mutex );
650
-
651
- ret = request_module ("cpufreq_%s" , str_governor );
652
- if (ret )
653
- return NULL ;
654
-
655
- mutex_lock (& cpufreq_governor_mutex );
661
+ t = get_governor (str_governor );
662
+ if (t )
663
+ return t ;
656
664
657
- t = find_governor (str_governor );
658
- }
659
- if (t && !try_module_get (t -> owner ))
660
- t = NULL ;
661
-
662
- mutex_unlock (& cpufreq_governor_mutex );
665
+ if (request_module ("cpufreq_%s" , str_governor ))
666
+ return NULL ;
663
667
664
- return t ;
668
+ return get_governor ( str_governor ) ;
665
669
}
666
670
667
671
/**
@@ -815,12 +819,14 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
815
819
goto out ;
816
820
}
817
821
822
+ mutex_lock (& cpufreq_governor_mutex );
818
823
for_each_governor (t ) {
819
824
if (i >= (ssize_t ) ((PAGE_SIZE / sizeof (char ))
820
825
- (CPUFREQ_NAME_LEN + 2 )))
821
- goto out ;
826
+ break ;
822
827
i += scnprintf (& buf [i ], CPUFREQ_NAME_PLEN , "%s " , t -> name );
823
828
}
829
+ mutex_unlock (& cpufreq_governor_mutex );
824
830
out :
825
831
i += sprintf (& buf [i ], "\n" );
826
832
return i ;
@@ -1058,15 +1064,17 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
1058
1064
struct cpufreq_governor * def_gov = cpufreq_default_governor ();
1059
1065
struct cpufreq_governor * gov = NULL ;
1060
1066
unsigned int pol = CPUFREQ_POLICY_UNKNOWN ;
1067
+ int ret ;
1061
1068
1062
1069
if (has_target ()) {
1063
1070
/* Update policy governor to the one used before hotplug. */
1064
- gov = find_governor (policy -> last_governor );
1071
+ gov = get_governor (policy -> last_governor );
1065
1072
if (gov ) {
1066
1073
pr_debug ("Restoring governor %s for cpu %d\n" ,
1067
1074
policy -> governor -> name , policy -> cpu );
1068
1075
} else if (def_gov ) {
1069
1076
gov = def_gov ;
1077
+ __module_get (gov -> owner );
1070
1078
} else {
1071
1079
return - ENODATA ;
1072
1080
}
@@ -1089,7 +1097,11 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
1089
1097
return - ENODATA ;
1090
1098
}
1091
1099
1092
- return cpufreq_set_policy (policy , gov , pol );
1100
+ ret = cpufreq_set_policy (policy , gov , pol );
1101
+ if (gov )
1102
+ module_put (gov -> owner );
1103
+
1104
+ return ret ;
1093
1105
}
1094
1106
1095
1107
static int cpufreq_add_policy_cpu (struct cpufreq_policy * policy , unsigned int cpu )
0 commit comments