[PATCH 01/12] clk: samsung: exynos5-subcmu: Detach power domain on add failure
From: Lee Jones
Date: Fri Nov 27 2026 - 13:04:35 EST
exynos5_clk_register_subcmu() attaches &pdev->dev to its generic power
domain via of_genpd_add_device(). If platform_device_add() then fails,
it frees pdev via platform_device_put() without detaching it from the
power domain, leaving a dangling device pointer in the genpd device
list.
Record the return value of of_genpd_add_device() (keeping attachment
non-fatal when power domains are disabled) and call
pm_genpd_remove_device() before putting pdev if platform_device_add()
fails.
Fixes: b06a532bf1fa ("clk: samsung: Add Exynos5 sub-CMU clock driver")
Closes: https://sashiko.dev/#/bug/linux-0f461223-0d95-4e2c-b3d1-eac8e585e532
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/clk/samsung/clk-exynos5-subcmu.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/samsung/clk-exynos5-subcmu.c b/drivers/clk/samsung/clk-exynos5-subcmu.c
index 373129847301..b0781e9f5640 100644
--- a/drivers/clk/samsung/clk-exynos5-subcmu.c
+++ b/drivers/clk/samsung/clk-exynos5-subcmu.c
@@ -137,7 +137,7 @@ static int __init exynos5_clk_register_subcmu(struct device *parent,
{
struct of_phandle_args genpdspec = { .np = pd_node };
struct platform_device *pdev;
- int ret;
+ int genpd_ret, ret;
pdev = platform_device_alloc("exynos5-subcmu", PLATFORM_DEVID_AUTO);
if (!pdev)
@@ -145,10 +145,13 @@ static int __init exynos5_clk_register_subcmu(struct device *parent,
pdev->dev.parent = parent;
platform_set_drvdata(pdev, (void *)info);
- of_genpd_add_device(&genpdspec, &pdev->dev);
+ genpd_ret = of_genpd_add_device(&genpdspec, &pdev->dev);
ret = platform_device_add(pdev);
- if (ret)
+ if (ret) {
+ if (!genpd_ret)
+ pm_genpd_remove_device(&pdev->dev);
platform_device_put(pdev);
+ }
return ret;
}
--
2.56.1.839.g22a8290db9-goog