]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drm/amdgpu: fix memory leak in CGS (FW info)
authorMykola Lysenko <Mykola.Lysenko@amd.com>
Wed, 30 Mar 2016 09:50:11 +0000 (05:50 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 5 May 2016 00:29:20 +0000 (20:29 -0400)
Previously requested FW pointer should not be
overwritten on a subsequent call.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Mykola Lysenko <Mykola.Lysenko@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c

index 837cdd2a6a2b8849c9287a536013fd3370afd041..490464e39322e7fe6b0184a14a867cb3d3ed0f58 100644 (file)
@@ -735,42 +735,44 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
                const uint8_t *src;
                const struct smc_firmware_header_v1_0 *hdr;
 
-               switch (adev->asic_type) {
-               case CHIP_TONGA:
-                       strcpy(fw_name, "amdgpu/tonga_smc.bin");
-                       break;
-               case CHIP_FIJI:
-                       strcpy(fw_name, "amdgpu/fiji_smc.bin");
-                       break;
-               case CHIP_POLARIS11:
-                       if (type == CGS_UCODE_ID_SMU)
-                               strcpy(fw_name, "amdgpu/polaris11_smc.bin");
-                       else if (type == CGS_UCODE_ID_SMU_SK)
-                               strcpy(fw_name, "amdgpu/polaris11_smc_sk.bin");
-                       break;
-               case CHIP_POLARIS10:
-                       if (type == CGS_UCODE_ID_SMU)
-                               strcpy(fw_name, "amdgpu/polaris10_smc.bin");
-                       else if (type == CGS_UCODE_ID_SMU_SK)
-                               strcpy(fw_name, "amdgpu/polaris10_smc_sk.bin");
-                       break;
-               default:
-                       DRM_ERROR("SMC firmware not supported\n");
-                       return -EINVAL;
-               }
+               if (!adev->pm.fw) {
+                       switch (adev->asic_type) {
+                       case CHIP_TONGA:
+                               strcpy(fw_name, "amdgpu/tonga_smc.bin");
+                               break;
+                       case CHIP_FIJI:
+                               strcpy(fw_name, "amdgpu/fiji_smc.bin");
+                               break;
+                       case CHIP_POLARIS11:
+                               if (type == CGS_UCODE_ID_SMU)
+                                       strcpy(fw_name, "amdgpu/polaris11_smc.bin");
+                               else if (type == CGS_UCODE_ID_SMU_SK)
+                                       strcpy(fw_name, "amdgpu/polaris11_smc_sk.bin");
+                               break;
+                       case CHIP_POLARIS10:
+                               if (type == CGS_UCODE_ID_SMU)
+                                       strcpy(fw_name, "amdgpu/polaris10_smc.bin");
+                               else if (type == CGS_UCODE_ID_SMU_SK)
+                                       strcpy(fw_name, "amdgpu/polaris10_smc_sk.bin");
+                               break;
+                       default:
+                               DRM_ERROR("SMC firmware not supported\n");
+                               return -EINVAL;
+                       }
 
-               err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
-               if (err) {
-                       DRM_ERROR("Failed to request firmware\n");
-                       return err;
-               }
+                       err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
+                       if (err) {
+                               DRM_ERROR("Failed to request firmware\n");
+                               return err;
+                       }
 
-               err = amdgpu_ucode_validate(adev->pm.fw);
-               if (err) {
-                       DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
-                       release_firmware(adev->pm.fw);
-                       adev->pm.fw = NULL;
-                       return err;
+                       err = amdgpu_ucode_validate(adev->pm.fw);
+                       if (err) {
+                               DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
+                               release_firmware(adev->pm.fw);
+                               adev->pm.fw = NULL;
+                               return err;
+                       }
                }
 
                hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;