Once the job scheduler has been initialized, failures from ethosu_init()
or drm_dev_register() return from probe without tearing it down. The
registration failure also leaves the SRAM-pool allocation in use, because
the platform remove callback is not called after a failed probe.

Unwind the initialized resources on both paths. Also do not call
drm_sched_fini() after a failed drm_sched_init(): the scheduler initializer
already unwinds its partial setup, while drm_sched_fini() requires a
successfully initialized scheduler.

Fixes: 5a5e9c0228e6 ("accel: Add Arm Ethos-U NPU driver")
Cc: [email protected]
Assisted-by: LLM
Signed-off-by: Rob Herring (Arm) <[email protected]>
---
v2:
 - Adjust for previous patch reworking runtime-PM suspend
---
 drivers/accel/ethosu/ethosu_drv.c | 13 ++++++++++++-
 drivers/accel/ethosu/ethosu_job.c |  6 +-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/accel/ethosu/ethosu_drv.c 
b/drivers/accel/ethosu/ethosu_drv.c
index 1f6fb5d18cf2..2c8d735767b2 100644
--- a/drivers/accel/ethosu/ethosu_drv.c
+++ b/drivers/accel/ethosu/ethosu_drv.c
@@ -375,9 +375,20 @@ static int ethosu_probe(struct platform_device *pdev)
 
        ret = ethosu_init(ethosudev);
        if (ret)
-               return ret;
+               goto err_job_fini;
 
        ret = drm_dev_register(&ethosudev->base, 0);
+       if (ret)
+               goto err_sram_free;
+
+       return 0;
+
+err_sram_free:
+       if (ethosudev->sram)
+               gen_pool_free(ethosudev->srampool, (unsigned 
long)ethosudev->sram,
+                             ethosudev->npu_info.sram_size);
+err_job_fini:
+       ethosu_job_fini(ethosudev);
        return ret;
 }
 
diff --git a/drivers/accel/ethosu/ethosu_job.c 
b/drivers/accel/ethosu/ethosu_job.c
index 8dce74db0cb4..ec65305e0cd7 100644
--- a/drivers/accel/ethosu/ethosu_job.c
+++ b/drivers/accel/ethosu/ethosu_job.c
@@ -355,14 +355,10 @@ int ethosu_job_init(struct ethosu_device *edev)
        ret = drm_sched_init(&edev->sched, &args);
        if (ret) {
                dev_err(dev, "Failed to create scheduler: %d\n", ret);
-               goto err_sched;
+               return ret;
        }
 
        return 0;
-
-err_sched:
-       drm_sched_fini(&edev->sched);
-       return ret;
 }
 
 void ethosu_job_fini(struct ethosu_device *dev)

-- 
2.53.0

Reply via email to