From c7ae23947d1afdfdccf282cd4199b1dde285df2d Mon Sep 17 00:00:00 2001 From: Jordan Crouse Date: Tue, 25 Feb 2020 13:33:13 -0700 Subject: [PATCH] msm: kgsl: Minor cleanups for kgsl bus probe The KGSL bus probe was not quite resilient for a deferred probe. Move a memory allocation to devm and make sure that the interconnect handle is properly put away on failure. Change-Id: Ic0dedbad261c483a157161a43da0b54459ed46ff Signed-off-by: Jordan Crouse --- drivers/gpu/msm/adreno.c | 28 ++++++++++++++-------------- drivers/gpu/msm/kgsl_bus.c | 9 ++------- drivers/gpu/msm/kgsl_gmu.c | 6 +++--- drivers/gpu/msm/kgsl_rgmu.c | 9 ++++++++- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/msm/adreno.c b/drivers/gpu/msm/adreno.c index 844870daac37..fccb227e2bc3 100644 --- a/drivers/gpu/msm/adreno.c +++ b/drivers/gpu/msm/adreno.c @@ -1462,10 +1462,8 @@ static int adreno_probe(struct platform_device *pdev) } status = kgsl_bus_init(device, pdev); - if (status) { - device->pdev = NULL; - return status; - } + if (status) + goto err; /* * Probe/init GMU after initial gpu power probe @@ -1473,10 +1471,8 @@ static int adreno_probe(struct platform_device *pdev) * needs GMU initialized. */ status = gmu_core_probe(device); - if (status) { - device->pdev = NULL; - return status; - } + if (status) + goto err; /* * The SMMU APIs use unsigned long for virtual addresses which means @@ -1492,10 +1488,8 @@ static int adreno_probe(struct platform_device *pdev) ADRENO_FEATURE(adreno_dev, ADRENO_CONTENT_PROTECTION)); status = kgsl_device_platform_probe(device); - if (status) { - device->pdev = NULL; - return status; - } + if (status) + goto err; /* Probe for the optional CX_DBGC block */ adreno_cx_dbgc_probe(device); @@ -1521,8 +1515,7 @@ static int adreno_probe(struct platform_device *pdev) status = PTR_ERR_OR_ZERO(device->memstore); if (status) { kgsl_device_platform_remove(device); - device->pdev = NULL; - return status; + goto err; } /* Initialize the snapshot engine */ @@ -1580,6 +1573,13 @@ static int adreno_probe(struct platform_device *pdev) #endif return 0; +err: + device->pdev = NULL; + + gmu_core_remove(device); + kgsl_bus_close(device); + + return status; } static void _adreno_free_memories(struct adreno_device *adreno_dev) diff --git a/drivers/gpu/msm/kgsl_bus.c b/drivers/gpu/msm/kgsl_bus.c index bddf3de31e97..d50e3e916da8 100644 --- a/drivers/gpu/msm/kgsl_bus.c +++ b/drivers/gpu/msm/kgsl_bus.c @@ -118,7 +118,7 @@ u32 *kgsl_bus_get_table(struct platform_device *pdev, if (num <= 0) return ERR_PTR(-EINVAL); - levels = kcalloc(num, sizeof(*levels), GFP_KERNEL); + levels = devm_kcalloc(&pdev->dev, num, sizeof(*levels), GFP_KERNEL); if (!levels) return ERR_PTR(-ENOMEM); @@ -172,10 +172,5 @@ done: void kgsl_bus_close(struct kgsl_device *device) { - struct kgsl_pwrctrl *pwr = &device->pwrctrl; - - kfree(pwr->ddr_table); - - /* FIXME: Make sure icc put can handle NULL or IS_ERR */ - icc_put(pwr->icc_path); + icc_put(device->pwrctrl.icc_path); } diff --git a/drivers/gpu/msm/kgsl_gmu.c b/drivers/gpu/msm/kgsl_gmu.c index 13432796a4a3..3920ad43a359 100644 --- a/drivers/gpu/msm/kgsl_gmu.c +++ b/drivers/gpu/msm/kgsl_gmu.c @@ -945,7 +945,7 @@ static int gmu_bus_vote_init(struct kgsl_device *device) if (count > 0) cnoc = build_rpmh_bw_votes(a660_cnoc_bcms, ARRAY_SIZE(a660_cnoc_bcms), cnoc_table, count); - kfree(cnoc_table); + devm_kfree(&device->pdev->dev, cnoc_table); if (IS_ERR(cnoc)) { free_rpmh_bw_votes(ddr); @@ -1746,8 +1746,8 @@ static void gmu_remove(struct kgsl_device *device) gmu->cx_gdsc = NULL; } - device->gmu_core.flags = 0; - device->gmu_core.ptr = NULL; + memset(&device->gmu_core, 0, sizeof(device->gmu_core)); + gmu->pdev = NULL; kfree(gmu); } diff --git a/drivers/gpu/msm/kgsl_rgmu.c b/drivers/gpu/msm/kgsl_rgmu.c index 40d5d8af0adb..0cc78e3ce50e 100644 --- a/drivers/gpu/msm/kgsl_rgmu.c +++ b/drivers/gpu/msm/kgsl_rgmu.c @@ -447,9 +447,16 @@ static bool rgmu_regulator_isenabled(struct kgsl_device *device) return (rgmu->gx_gdsc && regulator_is_enabled(rgmu->gx_gdsc)); } +static void rgmu_remove(struct kgsl_device *device) +{ + rgmu_stop(device); + + memset(&device->gmu_core, 0, sizeof(device->gmu_core)); +} + struct gmu_core_ops rgmu_ops = { .probe = rgmu_probe, - .remove = rgmu_stop, + .remove = rgmu_remove, .init = rgmu_init, .start = rgmu_start, .stop = rgmu_stop,