Skip to contentSkip to conversation

drm/amdgpu: fix null ptr access

PATCH Superseded Flora Cui 2 participants 2 messages Jan 13, 2022 – Jan 14, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Flora Cui

author
#0 lore raw

PATCH 1/1 drm/amdgpu: fix null ptr access

check null ptr first before access its element

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 2 +-
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -1
index f0daa66f5b3d..5fc33893a68c 100644
@@ -463,7 +463,7 @@ int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_versio
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	int r = 0;
 
-	if (!pp_funcs->load_firmware)
+	if (!pp_funcs || !pp_funcs->load_firmware)
 		return 0;
 
 	mutex_lock(&adev->pm.mutex);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
index 828cb932f6a9..aa640a9c6137 100644
@@ -3281,7 +3281,7 @@ void amdgpu_smu_stb_debug_fs_init(struct amdgpu_device *adev)
 
 	struct smu_context *smu = adev->powerplay.pp_handle;
 
-	if (!smu->stb_context.stb_buf_size)
+	if (!smu || !smu->stb_context.stb_buf_size)
 		return;
 
 	debugfs_create_file_size("amdgpu_smu_stb_dump",
Signature · 1 line
2.25.1
#1 lore raw

[AMD Official Use Only]

Quoted 22 lines

-----Original Message-----
From: Cui, Flora <[email protected]>
Sent: Thursday, January 13, 2022 2:58 PM
To: [email protected]; Quan, Evan <[email protected]>
Cc: Cui, Flora <[email protected]>
Subject: [PATCH] drm/amdgpu: fix null ptr access

check null ptr first before access its element

---
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c       | 2 +-
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index f0daa66f5b3d..5fc33893a68c 100644
@@ -463,7 +463,7 @@ int amdgpu_pm_load_smu_firmware(struct

amdgpu_device *adev, uint32_t *smu_versio

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_versio · line 467

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -1
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
 	int r = 0;
 
-	if (!pp_funcs->load_firmware)
+	if (!pp_funcs || !pp_funcs->load_firmware)
 		return 0;

[Quan, Evan] This seems fine to me.

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
 	mutex_lock(&adev->pm.mutex);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
index 828cb932f6a9..aa640a9c6137 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c void amdgpu_smu_stb_debug_fs_init(struct · line 3286

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
@@ -3281,7 +3281,7 @@ void amdgpu_smu_stb_debug_fs_init(struct
 amdgpu_device *adev)
 
 	struct smu_context *smu = adev->powerplay.pp_handle;
 
-	if (!smu->stb_context.stb_buf_size)
+	if (!smu || !smu->stb_context.stb_buf_size)
 		return;

[Quan, Evan] For this one, maybe as Lijo suggested, a check for "!adev->pm.dpm_enabled" in amdgpu_debugfs_pm_init() is better.

BR
Evan

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
 	debugfs_create_file_size("amdgpu_smu_stb_dump",
--

2.25.1