drm/amdgpu: Free ras cmd input buffer properly
authorHawking Zhang <Hawking.Zhang@amd.com>
Tue, 29 Aug 2023 15:20:27 +0000 (23:20 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 31 Aug 2023 22:12:13 +0000 (18:12 -0400)
Do not access the pointer for ras input cmd buffer
if it is even not allocated.

Signed-off-by: Hawking Zhang <Hawking.Zhang@amd.com>
Reviewed-by: Stanley Yang <Stanley.Yang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

index 378478c..3c4600e 100644 (file)
@@ -764,7 +764,7 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
 {
        struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
        union ta_ras_cmd_input *info;
-       int ret = 0;
+       int ret;
 
        if (!con)
                return -EINVAL;
@@ -773,7 +773,7 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
        if (enable &&
            head->block != AMDGPU_RAS_BLOCK__GFX &&
            !amdgpu_ras_is_feature_allowed(adev, head))
-               goto out;
+               return 0;
 
        /* Only enable gfx ras feature from host side */
        if (head->block == AMDGPU_RAS_BLOCK__GFX &&
@@ -801,16 +801,16 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
                                enable ? "enable":"disable",
                                get_ras_block_str(head),
                                amdgpu_ras_is_poison_mode_supported(adev), ret);
-                       goto out;
+                       return ret;
                }
+
+               kfree(info);
        }
 
        /* setup the obj */
        __amdgpu_ras_feature_enable(adev, head, enable);
-out:
-       if (head->block == AMDGPU_RAS_BLOCK__GFX)
-               kfree(info);
-       return ret;
+
+       return 0;
 }
 
 /* Only used in device probe stage and called only once. */