PM / Domains: Fix unsafe iteration over modified list of domains
authorKrzysztof Kozlowski <krzk@kernel.org>
Wed, 28 Jun 2017 14:56:20 +0000 (16:56 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 28 Jun 2017 23:24:35 +0000 (01:24 +0200)
of_genpd_remove_last() iterates over list of domains and removes
matching element thus it has to use safe version of list iteration.

Fixes: 17926551c98a (PM / Domains: Add support for removing nested PM domains by provider)
Cc: 4.9+ <stable@vger.kernel.org> # 4.9+
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
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 0b836fdc99ad4a1a96099af14f4dd3cf34c71c95..e342408cfb8d29028a3f3bd17fb8b50197da308b 100644 (file)
@@ -1980,14 +1980,14 @@ EXPORT_SYMBOL_GPL(of_genpd_add_subdomain);
  */
 struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
 {
-       struct generic_pm_domain *gpd, *genpd = ERR_PTR(-ENOENT);
+       struct generic_pm_domain *gpd, *tmp, *genpd = ERR_PTR(-ENOENT);
        int ret;
 
        if (IS_ERR_OR_NULL(np))
                return ERR_PTR(-EINVAL);
 
        mutex_lock(&gpd_list_lock);
-       list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
+       list_for_each_entry_safe(gpd, tmp, &gpd_list, gpd_list_node) {
                if (gpd->provider == &np->fwnode) {
                        ret = genpd_remove(gpd);
                        genpd = ret ? ERR_PTR(ret) : gpd;