Enhance error handling in function amdgpu_pci_probe() to avoid
possible resource leakage.

Signed-off-by: Jiang Liu <ge...@linux.alibaba.com>
Reviewed-by: Mario Limonciello <mario.limoncie...@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 3f26e850120c..f1378b867923 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2346,16 +2346,16 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
                msleep(5000);
                goto retry_init;
        } else if (ret) {
-               goto err_pci;
+               goto unload_kms;
        }
 
        ret = amdgpu_xcp_dev_register(adev, ent);
        if (ret)
-               goto err_pci;
+               goto unplug_drm;
 
        ret = amdgpu_amdkfd_drm_client_create(adev);
        if (ret)
-               goto err_pci;
+               goto deregister_xcp;
 
        /*
         * 1. don't init fbdev on hw without DCE
@@ -2424,6 +2424,12 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
 
        return 0;
 
+deregister_xcp:
+       amdgpu_xcp_dev_deregister(adev);
+unplug_drm:
+       drm_dev_unplug(ddev);
+unload_kms:
+       amdgpu_driver_unload_kms(ddev);
 err_pci:
        pci_disable_device(pdev);
        return ret;
-- 
2.43.5

Reply via email to