drm/amdgpu: check hive pointer before access
authorHawking Zhang <Hawking.Zhang@amd.com>
Sat, 5 Sep 2020 15:11:17 +0000 (23:11 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 13 Nov 2020 05:14:43 +0000 (00:14 -0500)
in case it is an invalid one

Signed-off-by: Hawking Zhang <Hawking.Zhang@amd.com>
Reviewed-by: Kevin Wang <kevin1.wang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c

index 54c358e71f9a7edb3cd533a33b79f32b27d4fcba..541ef6be390f09d0bfe55872acb9ed39b8ef6284 100644 (file)
@@ -395,12 +395,17 @@ void amdgpu_put_xgmi_hive(struct amdgpu_hive_info *hive)
 int amdgpu_xgmi_set_pstate(struct amdgpu_device *adev, int pstate)
 {
        int ret = 0;
-       struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
-       struct amdgpu_device *request_adev = hive->hi_req_gpu ?
-                                               hive->hi_req_gpu : adev;
+       struct amdgpu_hive_info *hive;
+       struct amdgpu_device *request_adev;
        bool is_hi_req = pstate == AMDGPU_XGMI_PSTATE_MAX_VEGA20;
-       bool init_low = hive->pstate == AMDGPU_XGMI_PSTATE_UNKNOWN;
+       bool init_low;
+
+       hive = amdgpu_get_xgmi_hive(adev);
+       if (!hive)
+               return 0;
 
+       request_adev = hive->hi_req_gpu ? hive->hi_req_gpu : adev;
+       init_low = hive->pstate == AMDGPU_XGMI_PSTATE_UNKNOWN;
        amdgpu_put_xgmi_hive(hive);
        /* fw bug so temporarily disable pstate switching */
        return 0;