* [PATCH] pmdomain: imx: gpc: Abort power-on on reset clock failure
@ 2026-11-29 19:25 Jiawen Liu
2026-11-29 19:43 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Jiawen Liu @ 2026-11-29 19:25 UTC (permalink / raw)
To: Ulf Hansson, Frank Li, Sascha Hauer
Cc: Pengutronix Kernel Team, Fabio Estevam, linux-pm, imx,
linux-arm-kernel
The i.MX6 GPC needs the domain's reset clocks running during power-up
so reset can propagate to its peripherals. On i.MX6SX, the PU domain's
GPU clock can fail to prepare when it uses a PLL3-derived parent and
PLL3 times out waiting for lock on first prepare. The driver still
requests power-up, disables and unprepares the failed clock, and reports
success. The unmatched cleanup can trigger clock framework warnings.
Abort before issuing the GPC request if clk_prepare_enable() fails.
Unwind the previously enabled clocks in reverse order, call
regulator_disable() if the domain supply was enabled, and return the
original error. Have both DT initialization paths release their clock
handles and return the error before initializing or registering the
domain.
The tool traced the error paths,
ran git diff --check and checkpatch, and built the ARM i.MX6 GPC object
with generic PM domains enabled and with PM disabled. Runtime and
hardware reproduction were not performed.
Fixes: 00eb60a8b4f7 ("ARM: imx6: gpc: Add PU power domain for GPU/VPU")
Signed-off-by: Jiawen Liu <liu1298662399@gmail.com>
---
drivers/pmdomain/imx/gpc.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/drivers/pmdomain/imx/gpc.c b/drivers/pmdomain/imx/gpc.c
index abca5f449a226..d881e4d61a40f 100644
--- a/drivers/pmdomain/imx/gpc.c
+++ b/drivers/pmdomain/imx/gpc.c
@@ -101,8 +101,11 @@ static int imx6_pm_domain_power_on(struct generic_pm_domain *genpd)
}
/* Enable reset clocks for all devices in the domain */
- for (i = 0; i < pd->num_clks; i++)
- clk_prepare_enable(pd->clk[i]);
+ for (i = 0; i < pd->num_clks; i++) {
+ ret = clk_prepare_enable(pd->clk[i]);
+ if (ret)
+ goto disable_clks;
+ }
/* Gate off domain when powered down */
regmap_update_bits(pd->regmap, pd->reg_offs + GPC_PGC_CTRL_OFFS,
@@ -126,6 +129,14 @@ static int imx6_pm_domain_power_on(struct generic_pm_domain *genpd)
clk_disable_unprepare(pd->clk[i]);
return 0;
+
+disable_clks:
+ while (i--)
+ clk_disable_unprepare(pd->clk[i]);
+ if (pd->supply)
+ regulator_disable(pd->supply);
+
+ return ret;
}
static int imx_pgc_get_clocks(struct device *dev, struct imx_pm_domain *domain)
@@ -191,8 +202,11 @@ static int imx_pgc_power_domain_probe(struct platform_device *pdev)
}
/* initially power on the domain */
- if (domain->base.power_on)
- domain->base.power_on(&domain->base);
+ if (domain->base.power_on) {
+ ret = domain->base.power_on(&domain->base);
+ if (ret)
+ goto put_clocks;
+ }
if (IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS)) {
pm_genpd_init(&domain->base, NULL, false);
@@ -207,6 +221,7 @@ static int imx_pgc_power_domain_probe(struct platform_device *pdev)
genpd_err:
pm_genpd_remove(&domain->base);
+put_clocks:
imx_pgc_put_clocks(domain);
return ret;
@@ -375,7 +390,9 @@ static int imx_gpc_old_dt_init(struct device *dev, struct regmap *regmap,
if (ret)
goto clk_err;
- domain->base.power_on(&domain->base);
+ ret = domain->base.power_on(&domain->base);
+ if (ret)
+ goto put_clocks;
}
}
@@ -394,6 +411,7 @@ static int imx_gpc_old_dt_init(struct device *dev, struct regmap *regmap,
genpd_err:
for (i = 0; i < num_domains; i++)
pm_genpd_remove(&imx_gpc_domains[i].base);
+put_clocks:
imx_pgc_put_clocks(&imx_gpc_domains[GPC_PGC_DOMAIN_PU]);
clk_err:
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pmdomain: imx: gpc: Abort power-on on reset clock failure
2026-11-29 19:25 [PATCH] pmdomain: imx: gpc: Abort power-on on reset clock failure Jiawen Liu
@ 2026-11-29 19:43 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 19:43 UTC (permalink / raw)
To: Jiawen Liu; +Cc: imx, Frank.Li
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] pmdomain: imx-gpc: use-after-free in imx_gpc_remove() [1]
--
commit 314d832218e82ea8e0176b8a53e992fc9028e2c4
Author: Jiawen Liu <liu1298662399@gmail.com>
pmdomain: imx: gpc: Abort power-on on reset clock failure
This commit aborts domain power-on in imx6_pm_domain_power_on() if
clk_prepare_enable() fails, unwinding enabled clocks and the domain supply
regulator and propagating the error to both DT initialization paths.
> diff --git a/drivers/pmdomain/imx/gpc.c b/drivers/pmdomain/imx/gpc.c
> index e0027459ad588..5e70997eb135b 100644
> --- a/drivers/pmdomain/imx/gpc.c
> +++ b/drivers/pmdomain/imx/gpc.c
[ ... ]
> @@ -394,6 +411,7 @@ static int imx_gpc_old_dt_init(struct device *dev, struct regmap *regmap,
> genpd_err:
> for (i = 0; i < num_domains; i++)
> pm_genpd_remove(&imx_gpc_domains[i].base);
> +put_clocks:
> imx_pgc_put_clocks(&imx_gpc_domains[GPC_PGC_DOMAIN_PU]);
> clk_err:
> return ret;
[Severity: Critical]
This problem wasn't introduced by this patch, but in the paired teardown
path imx_gpc_remove() [1], can an early return when pm_genpd_remove()
fails leave imx_gpc_domains[] registered after devm resources are freed?
drivers/pmdomain/imx/gpc.c:imx_gpc_remove() {
...
while (num_domains--) {
ret = pm_genpd_remove(&imx_gpc_domains[num_domains].base);
if (ret) {
dev_err(&pdev->dev,
"Failed to remove %s power domain (%pe)\n",
imx_gpc_domains[num_domains].base.name,
ERR_PTR(ret));
return;
}
if (num_domains == GPC_PGC_DOMAIN_PU)
imx_pgc_put_clocks(&imx_gpc_domains[num_domains]);
}
...
}
Because imx_gpc_remove() returns void, returning early does not abort device
unbind. The driver core still releases devm-managed resources such as the
domain regmap and supply regulator, so later genpd operations on the
remaining registered domains can trigger a use-after-free, and the PU domain
clocks are leaked.
[1] https://sashiko.dev/#/bug/linux-dc541c69-9965-4302-ab98-59f2bf3c23ca
--
Sashiko AI review · https://sashiko.dev/#/patchset/179598034233.2.15063208684049946861.pattern-ext-127.22@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 19:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 19:25 [PATCH] pmdomain: imx: gpc: Abort power-on on reset clock failure Jiawen Liu
2026-11-29 19:43 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox