diff mbox

[v2,4/8] PM / Domains: Fix unsafe iteration over modified list of device links

Message ID 20170612151748.7380-5-krzk@kernel.org (mailing list archive)
State Deferred
Headers show

Commit Message

Krzysztof Kozlowski June 12, 2017, 3:17 p.m. UTC
pm_genpd_remove_subdomain() iterates over domain's master_links list and
removes matching element thus it has to use safe version of list
iteration.

Fixes: f721889ff65a ("PM / Domains: Support for generic I/O PM domains (v8)")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/base/power/domain.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ulf Hansson June 13, 2017, 10:38 a.m. UTC | #1
On 12 June 2017 at 17:17, Krzysztof Kozlowski <krzk@kernel.org> wrote:
> pm_genpd_remove_subdomain() iterates over domain's master_links list and
> removes matching element thus it has to use safe version of list
> iteration.
>
> Fixes: f721889ff65a ("PM / Domains: Support for generic I/O PM domains (v8)")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

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

> ---
>  drivers/base/power/domain.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 9d3d3c2a5979..d1e438024e46 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -1400,7 +1400,7 @@ EXPORT_SYMBOL_GPL(pm_genpd_add_subdomain);
>  int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
>                               struct generic_pm_domain *subdomain)
>  {
> -       struct gpd_link *link;
> +       struct gpd_link *l, *link;
>         int ret = -EINVAL;
>
>         if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
> @@ -1416,7 +1416,7 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
>                 goto out;
>         }
>
> -       list_for_each_entry(link, &genpd->master_links, master_node) {
> +       list_for_each_entry_safe(link, l, &genpd->master_links, master_node) {
>                 if (link->slave != subdomain)
>                         continue;
>
> --
> 2.9.3
>
diff mbox

Patch

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 9d3d3c2a5979..d1e438024e46 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -1400,7 +1400,7 @@  EXPORT_SYMBOL_GPL(pm_genpd_add_subdomain);
 int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 			      struct generic_pm_domain *subdomain)
 {
-	struct gpd_link *link;
+	struct gpd_link *l, *link;
 	int ret = -EINVAL;
 
 	if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
@@ -1416,7 +1416,7 @@  int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 		goto out;
 	}
 
-	list_for_each_entry(link, &genpd->master_links, master_node) {
+	list_for_each_entry_safe(link, l, &genpd->master_links, master_node) {
 		if (link->slave != subdomain)
 			continue;