PM / Domains: Simplify genpd_lookup_dev()
authorUlf Hansson <ulf.hansson@linaro.org>
Thu, 29 Aug 2019 14:48:05 +0000 (16:48 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 2 Sep 2019 20:38:00 +0000 (22:38 +0200)
genpd_lookup_dev(), is a bit unnecessary heavy, as it walks the gpd_list to
try to find a valid PM domain corresponding to the device's attached genpd.

Instead of walking the gpd_list, let's use the fact that a genpd always has
the ->runtime_suspend() callback assigned to the genpd_runtime_suspend()
function.

While changing this, let's take the opportunity to also rename
genpd_lookup_dev(), into dev_to_genpd_safe() to better reflect its purpose.

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

index b063bc41b0a9cd9ba54fcad80955683131a65f8f..59d6f183d0bbd160edd2c31f28892e48ea788ac4 100644 (file)
@@ -149,29 +149,24 @@ static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev,
        return ret;
 }
 
+static int genpd_runtime_suspend(struct device *dev);
+
 /*
  * Get the generic PM domain for a particular struct device.
  * This validates the struct device pointer, the PM domain pointer,
  * and checks that the PM domain pointer is a real generic PM domain.
  * Any failure results in NULL being returned.
  */
-static struct generic_pm_domain *genpd_lookup_dev(struct device *dev)
+static struct generic_pm_domain *dev_to_genpd_safe(struct device *dev)
 {
-       struct generic_pm_domain *genpd = NULL, *gpd;
-
        if (IS_ERR_OR_NULL(dev) || IS_ERR_OR_NULL(dev->pm_domain))
                return NULL;
 
-       mutex_lock(&gpd_list_lock);
-       list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
-               if (&gpd->domain == dev->pm_domain) {
-                       genpd = gpd;
-                       break;
-               }
-       }
-       mutex_unlock(&gpd_list_lock);
+       /* A genpd's always have its ->runtime_suspend() callback assigned. */
+       if (dev->pm_domain->ops.runtime_suspend == genpd_runtime_suspend)
+               return pd_to_genpd(dev->pm_domain);
 
-       return genpd;
+       return NULL;
 }
 
 /*
@@ -1610,7 +1605,7 @@ static int genpd_remove_device(struct generic_pm_domain *genpd,
  */
 int pm_genpd_remove_device(struct device *dev)
 {
-       struct generic_pm_domain *genpd = genpd_lookup_dev(dev);
+       struct generic_pm_domain *genpd = dev_to_genpd_safe(dev);
 
        if (!genpd)
                return -EINVAL;