drm/msm/a6xx: fix error unwind in a6xx_gmu_wrapper_init()
Subsystems (4)
PATCH 1/1 drm/msm/a6xx: fix error unwind in a6xx_gmu_wrapper_init()
a6xx_gmu_wrapper_init() has three error-unwind bugs when initialization fails before gmu->initialized = true:
1) When a6xx_gmu_get_mmio() returns an ERR_PTR, goto err_mmio passes the error pointer directly to iounmap(gmu->mmio). Jump to err_clk instead.
2) When dev_pm_domain_attach_by_name(gmu->dev, "gx") returns an ERR_PTR (such as -EPROBE_DEFER), goto err_mmio skips detach_cxpd, leaking the attached gmu->cxpd domain and its runtime PM device link. Jump to detach_cxpd instead.
3) err_clk: drops the gmu->dev reference without calling pm_runtime_disable(gmu->dev) to balance pm_runtime_enable(gmu->dev), causing an unbalanced pm_runtime_enable() warning on the surviving GMU platform device across -EPROBE_DEFER retries. Call pm_runtime_disable(gmu->dev) at err_clk: before put_device(gmu->dev).
---
I am trying out a new Clang static analysis linter for ERR_PTR/NULL handling, and it flagged this code as possibly buggy. The findings were triaged and fixed with an AI coding assistant, then checked against linux-next (not runtime-tested on hardware).
Thanks,
Elkin
drivers/gpu/drm/msm/adreno/a6xx_gmu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gmu.c +3 -2
@@ -2290,7 +2290,7 @@ int a6xx_gmu_wrapper_init(struct a6xx_gpu *a6xx_gpu, struct device_node *node) gmu->mmio =a6xx_gmu_get_mmio (pdev, &start);if (IS_ERR (gmu->mmio)) { ret =PTR_ERR (gmu->mmio); - goto err_mmio; + goto err_clk; } res =platform_get_resource_byname (gpu->pdev,IORESOURCE_MEM ,"kgsl_3d0_reg_memory" );
@@ -2321,7 +2321,7 @@ int a6xx_gmu_wrapper_init(struct a6xx_gpu *a6xx_gpu, struct device_node *node) gmu->gxpd =dev_pm_domain_attach_by_name (gmu->dev,"gx" );if (IS_ERR (gmu->gxpd)) { ret =PTR_ERR (gmu->gxpd); - goto err_mmio; + goto detach_cxpd; } gmu->initialized = true;
@@ -2335,6 +2335,7 @@ int a6xx_gmu_wrapper_init(struct a6xx_gpu *a6xx_gpu, struct device_node *node)iounmap (gmu->mmio); err_clk: +pm_runtime_disable (gmu->dev);/* Drop reference taken in of_find_device_by_node */ put_device (gmu->dev);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog