@@ -1968,6 +1968,37 @@ static int genpd_set_default_power_state(struct generic_pm_domain *genpd)
19681968 return 0 ;
19691969}
19701970
1971+ static int genpd_alloc_data (struct generic_pm_domain * genpd )
1972+ {
1973+ int ret ;
1974+
1975+ if (genpd_is_cpu_domain (genpd ) &&
1976+ !zalloc_cpumask_var (& genpd -> cpus , GFP_KERNEL ))
1977+ return - ENOMEM ;
1978+
1979+ /* Use only one "off" state if there were no states declared */
1980+ if (genpd -> state_count == 0 ) {
1981+ ret = genpd_set_default_power_state (genpd );
1982+ if (ret )
1983+ goto free ;
1984+ }
1985+
1986+ return 0 ;
1987+
1988+ free :
1989+ if (genpd_is_cpu_domain (genpd ))
1990+ free_cpumask_var (genpd -> cpus );
1991+ return ret ;
1992+ }
1993+
1994+ static void genpd_free_data (struct generic_pm_domain * genpd )
1995+ {
1996+ if (genpd_is_cpu_domain (genpd ))
1997+ free_cpumask_var (genpd -> cpus );
1998+ if (genpd -> free_states )
1999+ genpd -> free_states (genpd -> states , genpd -> state_count );
2000+ }
2001+
19712002static void genpd_lock_init (struct generic_pm_domain * genpd )
19722003{
19732004 if (genpd -> flags & GENPD_FLAG_IRQ_SAFE ) {
@@ -2037,21 +2068,13 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
20372068 !genpd_status_on (genpd ))
20382069 return - EINVAL ;
20392070
2040- if (genpd_is_cpu_domain (genpd ) &&
2041- !zalloc_cpumask_var (& genpd -> cpus , GFP_KERNEL ))
2042- return - ENOMEM ;
2043-
2044- /* Use only one "off" state if there were no states declared */
2045- if (genpd -> state_count == 0 ) {
2046- ret = genpd_set_default_power_state (genpd );
2047- if (ret ) {
2048- if (genpd_is_cpu_domain (genpd ))
2049- free_cpumask_var (genpd -> cpus );
2050- return ret ;
2051- }
2052- } else if (!gov && genpd -> state_count > 1 ) {
2071+ /* Multiple states but no governor doesn't make sense. */
2072+ if (!gov && genpd -> state_count > 1 )
20532073 pr_warn ("%s: no governor for states\n" , genpd -> name );
2054- }
2074+
2075+ ret = genpd_alloc_data (genpd );
2076+ if (ret )
2077+ return ret ;
20552078
20562079 device_initialize (& genpd -> dev );
20572080 dev_set_name (& genpd -> dev , "%s" , genpd -> name );
@@ -2096,10 +2119,7 @@ static int genpd_remove(struct generic_pm_domain *genpd)
20962119 genpd_unlock (genpd );
20972120 genpd_debug_remove (genpd );
20982121 cancel_work_sync (& genpd -> power_off_work );
2099- if (genpd_is_cpu_domain (genpd ))
2100- free_cpumask_var (genpd -> cpus );
2101- if (genpd -> free_states )
2102- genpd -> free_states (genpd -> states , genpd -> state_count );
2122+ genpd_free_data (genpd );
21032123
21042124 pr_debug ("%s: removed %s\n" , __func__ , genpd -> name );
21052125
0 commit comments