[next] drm/amd/pp: don't dereference hwmgr until after it is null checked

Submitted by Colin King on March 22, 2018, 11:12 p.m.

Details

Message ID 20180322231239.16935-1-colin.king@canonical.com
State New
Headers show
Series "drm/amd/pp: don't dereference hwmgr until after it is null checked" ( rev: 1 ) in DRI devel

Not browsing as part of any series.

Commit Message

Colin King March 22, 2018, 11:12 p.m.
From: Colin Ian King <colin.king@canonical.com>

Pointer hwmgr is dereferenced before it is null checked, hence there
is a possibility of a null pointer dereference.  Fix this by only
dereferencing hwmgr once it is null checked.

Detected by CoverityScan, CID#1466428 ("Dereference before null check")

Fixes: 59156faf810e ("drm/amd/pp: Remove the cgs wrapper for notify smu version on APU")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c
index 8c49704b81af..6e88ed67e291 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c
@@ -698,18 +698,18 @@  static int smu8_start_smu(struct pp_hwmgr *hwmgr)
 {
 	int ret = 0;
 	uint32_t fw_to_check = 0;
-	struct amdgpu_device *adev = hwmgr->adev;
+	struct amdgpu_device *adev;
 
 	uint32_t index = SMN_MP1_SRAM_START_ADDR +
 			 SMU8_FIRMWARE_HEADER_LOCATION +
 			 offsetof(struct SMU8_Firmware_Header, Version);
 
-
 	if (hwmgr == NULL || hwmgr->device == NULL)
 		return -EINVAL;
 
 	cgs_write_register(hwmgr->device, mmMP0PUB_IND_INDEX, index);
 	hwmgr->smu_version = cgs_read_register(hwmgr->device, mmMP0PUB_IND_DATA);
+	adev = hwmgr->adev;
 	adev->pm.fw_version = hwmgr->smu_version >> 8;
 
 	fw_to_check = UCODE_ID_RLC_G_MASK |