[PATCH v3 2/8] PM / Domains: Handle safely genpd_syscore_switch() call on non-genpd device

From: Krzysztof Kozlowski
Date: Wed Jun 28 2017 - 10:59:06 EST


genpd_syscore_switch() had two problems:
1. It silently assumed that device, it is being called for, belongs to
generic power domain and used container_of() on its power domain
pointer. Such assumption might not be true always.

2. It iterated over list of generic power domains without holding
gpd_list_lock mutex thus list could have been modified in the same
time.

Usage of genpd_lookup_dev() solves both problems as it is safe a call
for non-generic power domains and uses mutex when iterating.

Reported-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
Signed-off-by: Krzysztof Kozlowski <krzk@xxxxxxxxxx>
Acked-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>

---

Not tested on real hardware.
---
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 01e31d9f6c94..d31a4434b8b3 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -1098,8 +1098,8 @@ static void genpd_syscore_switch(struct device *dev, bool suspend)
{
struct generic_pm_domain *genpd;

- genpd = dev_to_genpd(dev);
- if (!pm_genpd_present(genpd))
+ genpd = genpd_lookup_dev(dev);
+ if (!genpd)
return;

if (suspend) {
--
2.11.0