Skip to contentSkip to conversation

drm/amdgpu: fix a dereference on pointer hive before it is null checked

PATCH New Colin King 1 participant 1 message Apr 20, 2020

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 drm/amdgpu: fix a dereference on pointer hive before it is null checked

From: Colin Ian King <[email protected]>

Currently pointer hive is being dereferenced before it is being null checked and hence can lead to null pointer dereference issues. Fix this by only dereferencing pointer hive after it has been null checked.

Addresses-Coverity: ("Dereference before null check")

Fixes 25d4275e1931 ("drm/amdgpu: fix race between pstate and remote buffer map")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +5 -3
index 54d8a3e7e75c..2c0a59ba2826 100644
@@ -389,15 +389,17 @@ int amdgpu_xgmi_set_pstate(struct amdgpu_device *adev, int pstate)
 {
 	int ret = 0;
 	struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, 0);
-	struct amdgpu_device *request_adev = hive->hi_req_gpu ?
-						hive->hi_req_gpu : adev;
+	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;
 
 	/* fw bug so temporarily disable pstate switching */
 	if (!hive || adev->asic_type = CHIP_VEGA20)
 		return 0;
 
+	request_adev = hive->hi_req_gpu ? hive->hi_req_gpu : adev;
+	init_low = hive->pstate = AMDGPU_XGMI_PSTATE_UNKNOWN;
+
 	mutex_lock(&hive->hive_lock);
 
 	if (is_hi_req)
Signature · 1 line
2.25.1