drm/amdgpu:fix firmware memoryleak(v2)
authorMonk Liu <Monk.Liu@amd.com>
Tue, 19 Sep 2017 08:09:53 +0000 (16:09 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 26 Sep 2017 19:14:25 +0000 (15:14 -0400)
this fix memory leak due to request_firmware after driver
unloaded

v2:
release gmc firmware for gmc6/7/8 as well

Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c

index e02828665b14a5ec3fc3cc462a72d836fd721d2f..447d446b50150d475cb9a01945706b17bbfc2e78 100644 (file)
@@ -92,6 +92,12 @@ static int psp_sw_init(void *handle)
 
 static int psp_sw_fini(void *handle)
 {
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+
+       release_firmware(adev->psp.sos_fw);
+       adev->psp.sos_fw = NULL;
+       release_firmware(adev->psp.asd_fw);
+       adev->psp.asd_fw = NULL;
        return 0;
 }
 
index 9945218a548949873d14dfef3a97eb1de86b64ec..deeaee1457efdf1fa955ff0e01a07ae234e78d2f 100644 (file)
@@ -384,6 +384,25 @@ err1:
         return r;
 }
 
+
+static void gfx_v9_0_free_microcode(struct amdgpu_device *adev)
+{
+       release_firmware(adev->gfx.pfp_fw);
+       adev->gfx.pfp_fw = NULL;
+       release_firmware(adev->gfx.me_fw);
+       adev->gfx.me_fw = NULL;
+       release_firmware(adev->gfx.ce_fw);
+       adev->gfx.ce_fw = NULL;
+       release_firmware(adev->gfx.rlc_fw);
+       adev->gfx.rlc_fw = NULL;
+       release_firmware(adev->gfx.mec_fw);
+       adev->gfx.mec_fw = NULL;
+       release_firmware(adev->gfx.mec2_fw);
+       adev->gfx.mec2_fw = NULL;
+
+       kfree(adev->gfx.rlc.register_list_format);
+}
+
 static int gfx_v9_0_init_microcode(struct amdgpu_device *adev)
 {
        const char *chip_name;
@@ -1429,6 +1448,7 @@ static int gfx_v9_0_sw_fini(void *handle)
 
        gfx_v9_0_mec_fini(adev);
        gfx_v9_0_ngg_fini(adev);
+       gfx_v9_0_free_microcode(adev);
 
        return 0;
 }
index 2d1f3f651e1f57dde1fd4040b95c4dec0cbf4408..f4603a7c8ef32e193aa83f76d0380283ccc7cdc0 100644 (file)
@@ -901,6 +901,8 @@ static int gmc_v6_0_sw_fini(void *handle)
        gmc_v6_0_gart_fini(adev);
        amdgpu_gem_force_release(adev);
        amdgpu_bo_fini(adev);
+       release_firmware(adev->mc.fw);
+       adev->mc.fw = NULL;
 
        return 0;
 }
index 2256277d102f3b39f742684eb179ff12c7be8216..b0528ca9207b9e93846992ee2b756e7c08ecc3d6 100644 (file)
@@ -1050,6 +1050,8 @@ static int gmc_v7_0_sw_fini(void *handle)
        gmc_v7_0_gart_fini(adev);
        amdgpu_gem_force_release(adev);
        amdgpu_bo_fini(adev);
+       release_firmware(adev->mc.fw);
+       adev->mc.fw = NULL;
 
        return 0;
 }
index 114671b57004fe7d12dee863ffa9be53b1512d4d..f368cfe2f5851f7868a0f6b9aff95091b4e66490 100644 (file)
@@ -1147,6 +1147,8 @@ static int gmc_v8_0_sw_fini(void *handle)
        gmc_v8_0_gart_fini(adev);
        amdgpu_gem_force_release(adev);
        amdgpu_bo_fini(adev);
+       release_firmware(adev->mc.fw);
+       adev->mc.fw = NULL;
 
        return 0;
 }
index 61572c5d19efd15f1e28cedf543f3715d3b417a8..c26d205ff3bf4d632cdd0ff574e40d3adfd79f97 100644 (file)
@@ -1264,6 +1264,11 @@ static int sdma_v4_0_sw_fini(void *handle)
        for (i = 0; i < adev->sdma.num_instances; i++)
                amdgpu_ring_fini(&adev->sdma.instance[i].ring);
 
+       for (i = 0; i < adev->sdma.num_instances; i++) {
+               release_firmware(adev->sdma.instance[i].fw);
+               adev->sdma.instance[i].fw = NULL;
+       }
+
        return 0;
 }