Skip to contentSkip to conversation

pmdomain: rockchip: fix the probe error and deferral paths

PATCH Superseded Arun Iyengar 2 participants 5 messages Nov 13 – Nov 23

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover pmdomain: rockchip: fix the probe error and deferral paths

Fixes for a Rockchip power domain controller probe that fails or defers, for example on a domain clock that is not available yet. They apply on top of 1/2 of Yao Zi's series [1], which has to go in first; patch 2 replaces 2/2 of [1]. On the pmdomain next branch, 1/2 of [1] conflicts with "cycle an optional power-domain reset on power-on" in one line.

Tested with v1 on an Orange Pi 5 (RK3588S), v7.3 based kernel, with a test device tree that makes the PD_FEC clock appear late: no freed domain left on gpd_list, no -517 errors, and the controller binds later with all 26 domains. The v2/v3 changes are build-tested only.

[1] https://lore.kernel.org/r/[email protected]

Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.

---
Changes in v3:
- Split 2/2 into the fix (2/3: deferral, pm_qos error code, callers'
messages) and a clean-up of the other messages without Fixes tags
(3/3) (Yao Zi)
- Shorter commit messages and comments (Heiko Stuebner)
- No code change from v2 apart from the comments in 1/3
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Dropped "pmdomain: rockchip: put only the clocks that were got on
error" for 1/2 of [1], which fixes the same bug
- 2/2: drop the callers' messages and use dev_err_probe() where the
errors happen (Sebastian Reichel)
- 2/2: a pm_qos syscon error keeps its own code
- Link to v1: https://patch.msgid.link/[email protected]

---
Arun Iyengar (3):
pmdomain: rockchip: remove subdomain links before the domains on error
pmdomain: rockchip: don't report probe deferral as an error
pmdomain: rockchip: use dev_err_probe() for the other probe errors

 drivers/pmdomain/rockchip/pm-domains.c | 131 +++++++++++++++++++--------------
 1 file changed, 76 insertions(+), 55 deletions(-)

---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261110-pmdomain-rockchip-3497a2e7fdf5
prerequisite-patch-id: c2f0c5eb6651baa744f66342db63485a6685fb71

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>
#1 lore raw

PATCH v3 1/3 pmdomain: rockchip: remove subdomain links before the domains on error

When probe fails after some domains were registered, the cleanup calls pm_genpd_remove() in domain id order. That fails with -EBUSY for every domain that is still a parent. Reversing the order does not help: on RK3588 RKVDEC0/1 have a parent with a lower and one with a higher id. devm then frees those domains while they are still on gpd_list.

Remove the parent/child links first, depth first over the DT nodes.

Fixes 79d12b7a7f22 ("soc: rockchip: power-domain: use pm_genpd_remove in error cleanup")
---
 drivers/pmdomain/rockchip/pm-domains.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/pmdomain/rockchip/pm-domains.c +33 -0
index 86b5074b0469..df3f43d0c01b 100644
@@ -955,12 +955,45 @@ static void rockchip_pm_remove_one_domain(struct rockchip_pm_domain *pd)
 	/* devm will free our memory */
 }
 
+static struct generic_pm_domain *
+rockchip_pm_node_to_genpd(struct rockchip_pmu *pmu, struct device_node *node)
+{
+	u32 id;
+
+	if (of_property_read_u32(node, "reg", &id) ||
+	    id >= pmu->genpd_data.num_domains)
+		return NULL;
+
+	return pmu->genpd_data.domains[id];
+}
+
+/* Remove the links depth first, so each child has no subdomains left. */
+static void rockchip_pm_remove_subdomains(struct rockchip_pmu *pmu,
+					  struct device_node *parent)
+{
+	struct generic_pm_domain *parent_domain, *child_domain;
+
+	parent_domain = rockchip_pm_node_to_genpd(pmu, parent);
+
+	for_each_child_of_node_scoped(parent, np) {
+		rockchip_pm_remove_subdomains(pmu, np);
+
+		child_domain = rockchip_pm_node_to_genpd(pmu, np);
+		if (parent_domain && child_domain)
+			pm_genpd_remove_subdomain(parent_domain, child_domain);
+	}
+}
+
 static void rockchip_pm_domain_cleanup(struct rockchip_pmu *pmu)
 {
 	struct generic_pm_domain *genpd;
 	struct rockchip_pm_domain *pd;
 	int i;
 
+	/* pm_genpd_remove() refuses a domain that still has subdomains */
+	for_each_available_child_of_node_scoped(pmu->dev->of_node, np)
+		rockchip_pm_remove_subdomains(pmu, np);
+
 	for (i = 0; i < pmu->genpd_data.num_domains; i++) {
 		genpd = pmu->genpd_data.domains[i];
 		if (genpd) {
Signature · 1 line
2.55.0
#2 lore raw

PATCH v3 2/3 pmdomain: rockchip: don't report probe deferral as an error

In reply to Arun Iyengar

A domain clock that is not available yet is printed as an error by rockchip_pm_add_one_domain() and again by its callers, on every probe attempt. A pm_qos syscon that defers turns into -ENODEV and fails the probe.

Use dev_err_probe() where the errors happen, keep the syscon error code, and drop the callers' messages.

Yao Zi sent a patch for the clock message earlier [1] and agreed to drop it for this one.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")
Fixes 6be05b5ec161 ("soc: rockchip: power-domain: add support for sub-power domains")
Fixes 074c6a422d86 ("soc: rockchip: power-domain: support qos save and restore")
---
 drivers/pmdomain/rockchip/pm-domains.c | 37 +++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 19 deletions(-)
drivers/pmdomain/rockchip/pm-domains.c +18 -19
index df3f43d0c01b..a0b47d8c4b2a 100644
@@ -849,17 +849,20 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
 	for (i = 0; i < pd->num_clks; i++) {
 		pd->clks[i].clk = of_clk_get(node, i);
 		if (IS_ERR(pd->clks[i].clk)) {
-			error = PTR_ERR(pd->clks[i].clk);
-			dev_err(pmu->dev,
-				"%pOFn: failed to get clk at index %d: %d\n",
-				node, i, error);
+			error = dev_err_probe(pmu->dev,
+					      PTR_ERR(pd->clks[i].clk),
+					      "%pOFn: failed to get clk at index %d\n",
+					      node, i);
 			goto err_put_clocks;
 		}
 	}
 
 	error = clk_bulk_prepare(pd->num_clks, pd->clks);
-	if (error)
+	if (error) {
+		dev_err_probe(pmu->dev, error,
+			      "%pOFn: failed to prepare clocks\n", node);
 		goto err_put_clocks;
+	}
 
 	pd->num_qos = of_count_phandle_with_args(node, "pm_qos",
 						 NULL);
@@ -884,13 +887,18 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
 		for (j = 0; j < pd->num_qos; j++) {
 			qos_node = of_parse_phandle(node, "pm_qos", j);
 			if (!qos_node) {
-				error = -ENODEV;
+				error = dev_err_probe(pmu->dev, -ENODEV,
+						      "%pOFn: failed to get pm_qos %d\n",
+						      node, j);
 				goto err_unprepare_clocks;
 			}
 			pd->qos_regmap[j] = syscon_node_to_regmap(qos_node);
 			of_node_put(qos_node);
 			if (IS_ERR(pd->qos_regmap[j])) {
-				error = -ENODEV;
+				error = dev_err_probe(pmu->dev,
+						      PTR_ERR(pd->qos_regmap[j]),
+						      "%pOFn: failed to get pm_qos %d regmap\n",
+						      node, j);
 				goto err_unprepare_clocks;
 			}
 		}
@@ -1034,11 +1042,8 @@ static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu,
 		parent_domain = pmu->genpd_data.domains[idx];
 
 		error = rockchip_pm_add_one_domain(pmu, np);
-		if (error) {
-			dev_err(pmu->dev, "failed to handle node %pOFn: %d\n",
-				np, error);
+		if (error)
 			return error;
-		}
 
 		error = of_property_read_u32(np, "reg", &idx);
 		if (error) {
@@ -1128,18 +1133,12 @@ static int rockchip_pm_domain_probe(struct platform_device *pdev)
 
 	for_each_available_child_of_node_scoped(np, node) {
 		error = rockchip_pm_add_one_domain(pmu, node);
-		if (error) {
-			dev_err(dev, "failed to handle node %pOFn: %d\n",
-				node, error);
+		if (error)
 			goto err_out;
-		}
 
 		error = rockchip_pm_add_subdomain(pmu, node);
-		if (error < 0) {
-			dev_err(dev, "failed to handle subdomain node %pOFn: %d\n",
-				node, error);
+		if (error < 0)
 			goto err_out;
-		}
 	}
 
 	if (error) {
Signature · 1 line
2.55.0
#3 lore raw

PATCH v3 3/3 pmdomain: rockchip: use dev_err_probe() for the other probe errors

In reply to Arun Iyengar

Convert the remaining dev_err() and return pairs in the probe path to dev_err_probe(). The return values do not change.

---
 drivers/pmdomain/rockchip/pm-domains.c | 63 ++++++++++++++--------------------
 1 file changed, 26 insertions(+), 37 deletions(-)
drivers/pmdomain/rockchip/pm-domains.c +26 -37
index a0b47d8c4b2a..d132fdd11a56 100644
@@ -804,28 +804,22 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
 	int error;
 
 	error = of_property_read_u32(node, "reg", &id);
-	if (error) {
-		dev_err(pmu->dev,
-			"%pOFn: failed to retrieve domain id (reg): %d\n",
-			node, error);
-		return -EINVAL;
-	}
-
-	if (id >= pmu->info->num_domains) {
-		dev_err(pmu->dev, "%pOFn: invalid domain id %d\n",
-			node, id);
-		return -EINVAL;
-	}
+	if (error)
+		return dev_err_probe(pmu->dev, -EINVAL,
+				     "%pOFn: failed to retrieve domain id (reg)\n",
+				     node);
+
+	if (id >= pmu->info->num_domains)
+		return dev_err_probe(pmu->dev, -EINVAL,
+				     "%pOFn: invalid domain id %d\n", node, id);
 	/* RK3588 has domains with two parents (RKVDEC0/RKVDEC1) */
 	if (pmu->genpd_data.domains[id])
 		return 0;
 
 	pd_info = &pmu->info->domain_info[id];
-	if (!pd_info->pwr_mask && !pd_info->req_mask) {
-		dev_err(pmu->dev, "%pOFn: undefined domain id %d\n",
-			node, id);
-		return -EINVAL;
-	}
+	if (!pd_info->pwr_mask && !pd_info->req_mask)
+		return dev_err_probe(pmu->dev, -EINVAL,
+				     "%pOFn: undefined domain id %d\n", node, id);
 
 	pd = devm_kzalloc_obj(pmu->dev, *pd);
 	if (!pd)
@@ -1033,12 +1027,10 @@ static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu,
 		u32 idx;
 
 		error = of_property_read_u32(parent, "reg", &idx);
-		if (error) {
-			dev_err(pmu->dev,
-				"%pOFn: failed to retrieve domain id (reg): %d\n",
-				parent, error);
-			return error;
-		}
+		if (error)
+			return dev_err_probe(pmu->dev, error,
+					     "%pOFn: failed to retrieve domain id (reg)\n",
+					     parent);
 		parent_domain = pmu->genpd_data.domains[idx];
 
 		error = rockchip_pm_add_one_domain(pmu, np);
@@ -1046,23 +1038,20 @@ static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu,
 			return error;
 
 		error = of_property_read_u32(np, "reg", &idx);
-		if (error) {
-			dev_err(pmu->dev,
-				"%pOFn: failed to retrieve domain id (reg): %d\n",
-				np, error);
-			return error;
-		}
+		if (error)
+			return dev_err_probe(pmu->dev, error,
+					     "%pOFn: failed to retrieve domain id (reg)\n",
+					     np);
 		child_domain = pmu->genpd_data.domains[idx];
 
 		error = pm_genpd_add_subdomain(parent_domain, child_domain);
-		if (error) {
-			dev_err(pmu->dev, "%s failed to add subdomain %s: %d\n",
-				parent_domain->name, child_domain->name, error);
-			return error;
-		} else {
-			dev_dbg(pmu->dev, "%s add subdomain: %s\n",
-				parent_domain->name, child_domain->name);
-		}
+		if (error)
+			return dev_err_probe(pmu->dev, error,
+					     "%s failed to add subdomain %s\n",
+					     parent_domain->name, child_domain->name);
+
+		dev_dbg(pmu->dev, "%s add subdomain: %s\n",
+			parent_domain->name, child_domain->name);
 
 		error = rockchip_pm_add_subdomain(pmu, np);
 		if (error)
Signature · 1 line
2.55.0
#4 lore raw
In reply to Arun Iyengar
Quoted 6 lines · On Fri, Nov 13, 2026 at 9:42 AM Arun Iyengar via B4 Relay…

Fixes for a Rockchip power domain controller probe that fails or defers, for example on a domain clock that is not available yet. They apply on top of 1/2 of Yao Zi's series [1], which has to go in first; patch 2 replaces 2/2 of [1]. On the pmdomain next branch, 1/2 of [1] conflicts with "cycle an optional power-domain reset on power-on" in one line.

This sounds messy.

I tried to apply patch1 on my fixes branch which failed. Please re-base this and send a new version.

For changes that are targeted for fixes, please send them separately from the other improvements.

Kind regards
Uffe

Quoted 47 lines

Tested with v1 on an Orange Pi 5 (RK3588S), v7.3 based kernel, with a test device tree that makes the PD_FEC clock appear late: no freed domain left on gpd_list, no -517 errors, and the controller binds later with all 26 domains. The v2/v3 changes are build-tested only.

[1] https://lore.kernel.org/r/[email protected]

Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.

---
Changes in v3:
- Split 2/2 into the fix (2/3: deferral, pm_qos error code, callers'
messages) and a clean-up of the other messages without Fixes tags
(3/3) (Yao Zi)
- Shorter commit messages and comments (Heiko Stuebner)
- No code change from v2 apart from the comments in 1/3
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Dropped "pmdomain: rockchip: put only the clocks that were got on
error" for 1/2 of [1], which fixes the same bug
- 2/2: drop the callers' messages and use dev_err_probe() where the
errors happen (Sebastian Reichel)
- 2/2: a pm_qos syscon error keeps its own code
- Link to v1: https://patch.msgid.link/[email protected]

---
Arun Iyengar (3):
pmdomain: rockchip: remove subdomain links before the domains on error
pmdomain: rockchip: don't report probe deferral as an error
pmdomain: rockchip: use dev_err_probe() for the other probe errors

 drivers/pmdomain/rockchip/pm-domains.c | 131 +++++++++++++++++++--------------
 1 file changed, 76 insertions(+), 55 deletions(-)

---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261110-pmdomain-rockchip-3497a2e7fdf5
prerequisite-patch-id: c2f0c5eb6651baa744f66342db63485a6685fb71

Best regards,
--
Arun Iyengar <[email protected]>