[PATCH 2/3] drm/amdgpu/pm: Fix the null pointer dereference to pcurrent

Ma Jun Jun.Ma2 at amd.com
Fri May 10 09:41:16 UTC 2024


Check pcurrent pointer before using it to fix
the null pointer dereference

Signed-off-by: Ma Jun <Jun.Ma2 at amd.com>
---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
index f4bd8e9357e2..eb4cdadf8419 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
@@ -254,10 +254,16 @@ static void power_state_management(struct pp_hwmgr *hwmgr,
 
 	pcurrent = hwmgr->current_ps;
 
-	phm_apply_state_adjust_rules(hwmgr, requested, pcurrent);
-	if (pcurrent == NULL || (0 != phm_check_states_equal(hwmgr,
-			&pcurrent->hardware, &requested->hardware, &equal)))
+	if (pcurrent) {
+		phm_apply_state_adjust_rules(hwmgr, requested, pcurrent);
+		if (phm_check_states_equal(hwmgr,
+				&pcurrent->hardware, &requested->hardware, &equal))
+			equal = false;
+		else
+			equal = true;
+	} else {
 		equal = false;
+	}
 
 	if (!equal || phm_check_smc_update_required_for_display_configuration(hwmgr)) {
 		phm_set_power_state(hwmgr, &pcurrent->hardware, &requested->hardware);
-- 
2.34.1



More information about the amd-gfx mailing list