]> git.karo-electronics.de Git - linux-beck.git/commitdiff
PM / Domains: Verify the PM domain is present when adding a provider
authorJon Hunter <jonathanh@nvidia.com>
Mon, 12 Sep 2016 11:01:10 +0000 (12:01 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 13 Sep 2016 00:49:33 +0000 (02:49 +0200)
When a PM domain provider is added, there is currently no way to tell if
any PM domains associated with the provider are present. Naturally, the
PM domain provider should not be registered if the PM domains have not
been added. Nonetheless, verify that the PM domain(s) associated with a
provider are present when registering the PM domain provider.

This change adds a dependency on the function pm_genpd_present() when
CONFIG_PM_GENERIC_DOMAINS_OF is enabled and so ensure this function is
available when CONFIG_PM_GENERIC_DOMAINS_OF selected.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/domain.c

index c93aa3a6483958b87719adb66e1d118467f94a8b..fc9f11c26eec4d7c4483bd4d612ddf347ce5a046 100644 (file)
@@ -586,7 +586,7 @@ static int __init genpd_poweroff_unused(void)
 }
 late_initcall(genpd_poweroff_unused);
 
-#ifdef CONFIG_PM_SLEEP
+#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_GENERIC_DOMAINS_OF)
 
 /**
  * pm_genpd_present - Check if the given PM domain has been initialized.
@@ -606,6 +606,10 @@ static bool pm_genpd_present(const struct generic_pm_domain *genpd)
        return false;
 }
 
+#endif
+
+#ifdef CONFIG_PM_SLEEP
+
 static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd,
                                    struct device *dev)
 {
@@ -1453,7 +1457,19 @@ static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
 int of_genpd_add_provider_simple(struct device_node *np,
                                 struct generic_pm_domain *genpd)
 {
-       return genpd_add_provider(np, genpd_xlate_simple, genpd);
+       int ret = -EINVAL;
+
+       if (!np || !genpd)
+               return -EINVAL;
+
+       mutex_lock(&gpd_list_lock);
+
+       if (pm_genpd_present(genpd))
+               ret = genpd_add_provider(np, genpd_xlate_simple, genpd);
+
+       mutex_unlock(&gpd_list_lock);
+
+       return ret;
 }
 EXPORT_SYMBOL_GPL(of_genpd_add_provider_simple);
 
@@ -1465,7 +1481,26 @@ EXPORT_SYMBOL_GPL(of_genpd_add_provider_simple);
 int of_genpd_add_provider_onecell(struct device_node *np,
                                  struct genpd_onecell_data *data)
 {
-       return genpd_add_provider(np, genpd_xlate_onecell, data);
+       unsigned int i;
+       int ret;
+
+       if (!np || !data)
+               return -EINVAL;
+
+       mutex_lock(&gpd_list_lock);
+
+       for (i = 0; i < data->num_domains; i++) {
+               if (!pm_genpd_present(data->domains[i])) {
+                       mutex_unlock(&gpd_list_lock);
+                       return -EINVAL;
+               }
+       }
+
+       ret = genpd_add_provider(np, genpd_xlate_onecell, data);
+
+       mutex_unlock(&gpd_list_lock);
+
+       return ret;
 }
 EXPORT_SYMBOL_GPL(of_genpd_add_provider_onecell);