[PATCH] pmdomain: sunxi: Unregister D1 PPU domains on driver removal

Tian Xuechen 202300460064 at mail.sdu.edu.cn
Sat Nov 28 03:02:22 PST 2026


From: Tian Xuechen <202300460064 at mail.sdu.edu.cn>

The D1 PPU driver leaves its provider and power domains registered on
module unload. Delete the provider and remove each domain that was
initialized. Also unwind these domains if provider registration fails.

This issue was found by our static analysis tool under development.

Fixes: 0e30ca5ab0a8 ("soc: sunxi: Add Allwinner D1 PPU driver")
Signed-off-by: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
---
 drivers/pmdomain/sunxi/sun20i-ppu.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/pmdomain/sunxi/sun20i-ppu.c b/drivers/pmdomain/sunxi/sun20i-ppu.c
index 6af1dcad4a76..7a539e09f614 100644
--- a/drivers/pmdomain/sunxi/sun20i-ppu.c
+++ b/drivers/pmdomain/sunxi/sun20i-ppu.c
@@ -99,6 +99,19 @@ static int sun20i_ppu_pd_power_off(struct generic_pm_domain *genpd)
 	return sun20i_ppu_pd_set_power(pd, false);
 }
 
+static void sun20i_ppu_remove_domains(struct genpd_onecell_data *ppu)
+{
+	for (unsigned int i = 0; i < ppu->num_domains; i++)
+		if (ppu->domains[i])
+			pm_genpd_remove(ppu->domains[i]);
+}
+
+static void sun20i_ppu_remove(struct platform_device *pdev)
+{
+	of_genpd_del_provider(pdev->dev.of_node);
+	sun20i_ppu_remove_domains(platform_get_drvdata(pdev));
+}
+
 static int sun20i_ppu_probe(struct platform_device *pdev)
 {
 	const struct sun20i_ppu_desc *desc;
@@ -164,10 +177,12 @@ static int sun20i_ppu_probe(struct platform_device *pdev)
 	}
 
 	ret = of_genpd_add_provider_onecell(dev->of_node, ppu);
-	if (ret)
+	if (ret) {
 		dev_warn(dev, "Failed to add provider: %d\n", ret);
+		sun20i_ppu_remove_domains(ppu);
+	}
 
-	return 0;
+	return ret;
 }
 
 static const char *const sun20i_d1_ppu_pd_names[] = {
@@ -224,6 +239,7 @@ MODULE_DEVICE_TABLE(of, sun20i_ppu_of_match);
 
 static struct platform_driver sun20i_ppu_driver = {
 	.probe	= sun20i_ppu_probe,
+	.remove	= sun20i_ppu_remove,
 	.driver	= {
 		.name			= "sun20i-ppu",
 		.of_match_table		= sun20i_ppu_of_match,

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
-- 
2.43.0




More information about the linux-arm-kernel mailing list