diff mbox series

PM / Domains: Convert to dev_to_genpd_safe() in genpd_syscore_switch()

Message ID 20191016141649.18690-1-ulf.hansson@linaro.org
State Accepted
Commit fe0c2baae0bd47958991f13fb7551bf1328b4ea7
Headers show
Series PM / Domains: Convert to dev_to_genpd_safe() in genpd_syscore_switch() | expand

Commit Message

Ulf Hansson Oct. 16, 2019, 2:16 p.m. UTC
The intent with walking the gpd_list via calling genpd_present() from
genpd_syscore_switch(), is to make sure the dev->pm_domain pointer belongs
to a registered genpd. However, as a genpd can't be removed if there is a
device attached to it, let's convert to use the quicker dev_to_genpd_safe()
instead.

Due to the above change, this allows us to cleanup genpd_present() and move
it inside CONFIG_PM_GENERIC_DOMAINS_OF, so let's do that as well.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

---
 drivers/base/power/domain.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

-- 
2.17.1

Comments

Rafael J. Wysocki Nov. 13, 2019, 11:05 a.m. UTC | #1
On Wednesday, October 16, 2019 4:16:49 PM CET Ulf Hansson wrote:
> The intent with walking the gpd_list via calling genpd_present() from

> genpd_syscore_switch(), is to make sure the dev->pm_domain pointer belongs

> to a registered genpd. However, as a genpd can't be removed if there is a

> device attached to it, let's convert to use the quicker dev_to_genpd_safe()

> instead.

> 

> Due to the above change, this allows us to cleanup genpd_present() and move

> it inside CONFIG_PM_GENERIC_DOMAINS_OF, so let's do that as well.

> 

> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

> ---

>  drivers/base/power/domain.c | 32 ++++++++++++--------------------

>  1 file changed, 12 insertions(+), 20 deletions(-)

> 

> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c

> index cc85e87eaf05..600ea78d6b71 100644

> --- a/drivers/base/power/domain.c

> +++ b/drivers/base/power/domain.c

> @@ -922,24 +922,6 @@ static int __init genpd_power_off_unused(void)

>  }

>  late_initcall(genpd_power_off_unused);

>  

> -#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_GENERIC_DOMAINS_OF)

> -

> -static bool genpd_present(const struct generic_pm_domain *genpd)

> -{

> -	const struct generic_pm_domain *gpd;

> -

> -	if (IS_ERR_OR_NULL(genpd))

> -		return false;

> -

> -	list_for_each_entry(gpd, &gpd_list, gpd_list_node)

> -		if (gpd == genpd)

> -			return true;

> -

> -	return false;

> -}

> -

> -#endif

> -

>  #ifdef CONFIG_PM_SLEEP

>  

>  /**

> @@ -1354,8 +1336,8 @@ static void genpd_syscore_switch(struct device *dev, bool suspend)

>  {

>  	struct generic_pm_domain *genpd;

>  

> -	genpd = dev_to_genpd(dev);

> -	if (!genpd_present(genpd))

> +	genpd = dev_to_genpd_safe(dev);

> +	if (!genpd)

>  		return;

>  

>  	if (suspend) {

> @@ -2020,6 +2002,16 @@ static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,

>  	return 0;

>  }

>  

> +static bool genpd_present(const struct generic_pm_domain *genpd)

> +{

> +	const struct generic_pm_domain *gpd;

> +

> +	list_for_each_entry(gpd, &gpd_list, gpd_list_node)

> +		if (gpd == genpd)

> +			return true;

> +	return false;

> +}

> +

>  /**

>   * of_genpd_add_provider_simple() - Register a simple PM domain provider

>   * @np: Device node pointer associated with the PM domain provider.

> 


Applying as 5.5 material, thanks!
diff mbox series

Patch

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index cc85e87eaf05..600ea78d6b71 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -922,24 +922,6 @@  static int __init genpd_power_off_unused(void)
 }
 late_initcall(genpd_power_off_unused);
 
-#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_GENERIC_DOMAINS_OF)
-
-static bool genpd_present(const struct generic_pm_domain *genpd)
-{
-	const struct generic_pm_domain *gpd;
-
-	if (IS_ERR_OR_NULL(genpd))
-		return false;
-
-	list_for_each_entry(gpd, &gpd_list, gpd_list_node)
-		if (gpd == genpd)
-			return true;
-
-	return false;
-}
-
-#endif
-
 #ifdef CONFIG_PM_SLEEP
 
 /**
@@ -1354,8 +1336,8 @@  static void genpd_syscore_switch(struct device *dev, bool suspend)
 {
 	struct generic_pm_domain *genpd;
 
-	genpd = dev_to_genpd(dev);
-	if (!genpd_present(genpd))
+	genpd = dev_to_genpd_safe(dev);
+	if (!genpd)
 		return;
 
 	if (suspend) {
@@ -2020,6 +2002,16 @@  static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
 	return 0;
 }
 
+static bool genpd_present(const struct generic_pm_domain *genpd)
+{
+	const struct generic_pm_domain *gpd;
+
+	list_for_each_entry(gpd, &gpd_list, gpd_list_node)
+		if (gpd == genpd)
+			return true;
+	return false;
+}
+
 /**
  * of_genpd_add_provider_simple() - Register a simple PM domain provider
  * @np: Device node pointer associated with the PM domain provider.