linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PM: domains: Don't attach a device to genpd that corresponds to a provider
@ 2021-07-09 12:56 Ulf Hansson
  2021-07-09 13:06 ` Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Ulf Hansson @ 2021-07-09 12:56 UTC (permalink / raw)
  To: Rafael J . Wysocki, linux-pm
  Cc: Bjorn Andersson, Stephen Boyd, Saravana Kannan, Dmitry Baryshkov,
	Kevin Hilman, Geert Uytterhoeven, Ulf Hansson, linux-kernel

According to the common power domain DT bindings, a power domain provider
must have a "#power-domain-cells" property in its OF node. Additionally, if
a provider has a "power-domains" property, it means that it has a parent
domain.

It has turned out that some OF nodes that represents a genpd provider may
also be compatible with a regular platform device. This leads to, during
probe, genpd_dev_pm_attach(), genpd_dev_pm_attach_by_name() and
genpd_dev_pm_attach_by_id() tries to attach the corresponding struct device
to the genpd provider's parent domain, which is wrong. Instead the genpd
provider should only assign a parent domain, through
pm_genpd_add_subdomain() or of_genpd_add_subdomain().

Let's fix this problem in genpd by checking for the "#power-domain-cells"
property in the OF node for the struct device that is about to be attached.

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

This turned up when I was reviewing a couple of genpd realted Qcom patches [1],
from Dmitry Baryshkov (on cc).

I haven't been able to run much tests, so help with that would be greatly
appreciated. If someone encounter issues, I am happy to help to fix those.

Kind regards
Ulf Hansson

[1]
https://lkml.org/lkml/2021/7/9/7
https://lkml.org/lkml/2021/7/9/8

---
 drivers/base/power/domain.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index a934c679e6ce..21991fb56a19 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2699,6 +2699,10 @@ int genpd_dev_pm_attach(struct device *dev)
 	if (!dev->of_node)
 		return 0;
 
+	/* Don't try to attach a genpd provider. */
+	if (of_find_property(dev->of_node, "#power-domain-cells", NULL))
+		return NULL;
+
 	/*
 	 * Devices with multiple PM domains must be attached separately, as we
 	 * can only attach one PM domain per device.
@@ -2737,6 +2741,10 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
 	if (!dev->of_node)
 		return NULL;
 
+	/* Don't try to attach a genpd provider. */
+	if (of_find_property(dev->of_node, "#power-domain-cells", NULL))
+		return NULL;
+
 	/* Verify that the index is within a valid range. */
 	num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
 						 "#power-domain-cells");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-07-09 19:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 12:56 [PATCH] PM: domains: Don't attach a device to genpd that corresponds to a provider Ulf Hansson
2021-07-09 13:06 ` Geert Uytterhoeven
2021-07-09 13:22   ` Ulf Hansson
2021-07-09 13:35     ` Geert Uytterhoeven
2021-07-09 13:48       ` Ulf Hansson
2021-07-09 13:57         ` Geert Uytterhoeven
2021-07-09 14:02           ` Ulf Hansson
2021-07-09 13:46     ` Bjorn Andersson
2021-07-09 13:58       ` Ulf Hansson
2021-07-09 14:16         ` Bjorn Andersson
2021-07-09 18:49 ` kernel test robot
2021-07-09 19:01 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).