Skip to contentSkip to conversation

PM / Domains: Ensure subdomain is not in use before removing

RFC PATCH In review Jon Hunter 3 participants 5 messages Aug 27, 2015 – Sep 3, 2015

Subsystems (4)
lore
Share & tools
lore

Jon Hunter

author
#0 lore raw

RFC PATCH 1/1 PM / Domains: Ensure subdomain is not in use before removing

The function pm_genpd_remove_subdomain() removes a subdomain from a generic PM domain, however, it does not check if the subdomain has any slave domains or device attached before doing so. Therefore, add a test to verify that the subdomain does not have any slave domains associated or any device attached before removing.

---
 drivers/base/power/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/power/domain.c +6 -0
index 27888a90ca98..a3ed71d8129a 100644
@@ -1469,6 +1469,11 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 
 	mutex_lock(&genpd->lock);
 
+	if (!list_empty(&subdomain->slave_links) || subdomain->device_count) {
+		ret = -EBUSY;
+		goto out;
+	}
+
 	list_for_each_entry(link, &genpd->master_links, master_node) {
 		if (link->slave != subdomain)
 			continue;
@@ -1487,6 +1492,7 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 		break;
 	}
 
+out:
 	mutex_unlock(&genpd->lock);
 
 	return ret;
Signature · 1 line
2.1.4
#1 lore raw

Hi Jon,

Quoted 5 lines · Jon Hunter

The function pm_genpd_remove_subdomain() removes a subdomain from a generic PM domain, however, it does not check if the subdomain has any slave domains or device attached before doing so. Therefore, add a test to verify that the subdomain does not have any slave domains associated or any device attached before removing.

So far no-one ran into this, as there are no callers of pm_genpd_remove_subdomain() in mainline or -next.

Do you plan to add a caller?

Quoted 30 lines
---
 drivers/base/power/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/power/domain.c +6 -1
index 27888a90ca98..a3ed71d8129a 100644
@@ -1469,6 +1469,11 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 
        mutex_lock(&genpd->lock);
 
+       if (!list_empty(&subdomain->slave_links) || subdomain->device_count) {
+               ret = -EBUSY;
+               goto out;
+       }
+
        list_for_each_entry(link, &genpd->master_links, master_node) {
                if (link->slave != subdomain)
                        continue;
@@ -1487,6 +1492,7 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
                break;
        }
 
+out:
        mutex_unlock(&genpd->lock);
 
        return ret;
--
Quoted 1 line

2.1.4

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author
#2 lore raw

Hi Geert,

Quoted 9 lines · Geert Uytterhoeven

Hi Jon,

Quoted 5 lines · Jon Hunter

The function pm_genpd_remove_subdomain() removes a subdomain from a generic PM domain, however, it does not check if the subdomain has any slave domains or device attached before doing so. Therefore, add a test to verify that the subdomain does not have any slave domains associated or any device attached before removing.

Quoted 4 lines

So far no-one ran into this, as there are no callers of pm_genpd_remove_subdomain() in mainline or -next.

Do you plan to add a caller?

Yes exactly. However, given that the API was present I thought why not fix it now or at least get some feedback on this.

I have also noticed that there is no function to remove a pm-domain (ie. reverse of pm_genpd_init()). I assume that currently people add pm-domains and never remove them, which makes sense, however the scenario I am trying to solve is allowing the registering of pm-domains to be deferred if something is not yet present (ie. a regulator).

Cheers
Jon

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

Acked-by on v1 1/1
#3 lore raw
In reply to Jon Hunter
Quoted 16 lines · Jon Hunter

The function pm_genpd_remove_subdomain() removes a subdomain from a generic PM domain, however, it does not check if the subdomain has any slave domains or device attached before doing so. Therefore, add a test to verify that the subdomain does not have any slave domains associated or any device attached before removing.

---
 drivers/base/power/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/power/domain.c +0 -0
index 27888a90ca98..a3ed71d8129a 100644

drivers/base/power/domain.c int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, · line 1472

Quoted 4 lines
drivers/base/power/domain.c +1 -0
@@ -1469,6 +1469,11 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 
 	mutex_lock(&genpd->lock);
 
+	if (!list_empty(&subdomain->slave_links) || subdomain->device_count) {

maybe a pr_warn() or similar is appropriate here?

drivers/base/power/domain.c int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, · line 1476

Quoted 4 lines
drivers/base/power/domain.c +4 -0
+		ret = -EBUSY;
+		goto out;
+	}
+

... otherwise looks like a good check to add.

author
#4 lore raw
Quoted 19 lines · Kevin Hilman
Quoted 17 lines · Jon Hunter

The function pm_genpd_remove_subdomain() removes a subdomain from a generic PM domain, however, it does not check if the subdomain has any slave domains or device attached before doing so. Therefore, add a test to verify that the subdomain does not have any slave domains associated or any device attached before removing.

---
 drivers/base/power/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/power/domain.c +0 -0
index 27888a90ca98..a3ed71d8129a 100644
@@ -1469,6 +1469,11 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 
Quoted 5 lines

drivers/base/power/domain.c int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, · line 1472

Quoted 3 lines
drivers/base/power/domain.c +1 -0
 	mutex_lock(&genpd->lock);
 
+	if (!list_empty(&subdomain->slave_links) || subdomain->device_count) {

maybe a pr_warn() or similar is appropriate here?

Thanks, good suggestion. Will add.

Quoted 8 lines

drivers/base/power/domain.c int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, · line 1476

Quoted 4 lines
drivers/base/power/domain.c +4 -0
+		ret = -EBUSY;
+		goto out;
+	}
+

... otherwise looks like a good check to add.

Cheers
Jon

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------