Commit d19fb100 authored by Ma Jun's avatar Ma Jun Committed by Alex Deucher
Browse files

drm/amdgpu/pm: Fix the null pointer dereference in apply_state_adjust_rules



Check the pointer value to fix potential null pointer
dereference

Acked-by: default avatarYang <Wang&lt;kevinyang.wang@amd.com>
Signed-off-by: default avatarMa Jun <Jun.Ma2@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent b2aa3d4b
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -3314,8 +3314,7 @@ static int smu7_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
			const struct pp_power_state *current_ps)
{
	struct amdgpu_device *adev = hwmgr->adev;
	struct smu7_power_state *smu7_ps =
				cast_phw_smu7_power_state(&request_ps->hardware);
	struct smu7_power_state *smu7_ps;
	uint32_t sclk;
	uint32_t mclk;
	struct PP_Clocks minimum_clocks = {0};
@@ -3332,6 +3331,10 @@ static int smu7_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
	uint32_t latency;
	bool latency_allowed = false;

	smu7_ps = cast_phw_smu7_power_state(&request_ps->hardware);
	if (!smu7_ps)
		return -EINVAL;

	data->battery_state = (PP_StateUILabel_Battery ==
			request_ps->classification.ui_label);
	data->mclk_ignore_signal = false;
+8 −6
Original line number Diff line number Diff line
@@ -1074,16 +1074,18 @@ static int smu8_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
				struct pp_power_state  *prequest_ps,
			const struct pp_power_state *pcurrent_ps)
{
	struct smu8_power_state *smu8_ps =
				cast_smu8_power_state(&prequest_ps->hardware);

	const struct smu8_power_state *smu8_current_ps =
				cast_const_smu8_power_state(&pcurrent_ps->hardware);

	struct smu8_power_state *smu8_ps;
	const struct smu8_power_state *smu8_current_ps;
	struct smu8_hwmgr *data = hwmgr->backend;
	struct PP_Clocks clocks = {0, 0, 0, 0};
	bool force_high;

	smu8_ps = cast_smu8_power_state(&prequest_ps->hardware);
	smu8_current_ps = cast_const_smu8_power_state(&pcurrent_ps->hardware);

	if (!smu8_ps || !smu8_current_ps)
		return -EINVAL;

	smu8_ps->need_dfs_bypass = true;

	data->battery_state = (PP_StateUILabel_Battery == prequest_ps->classification.ui_label);
+5 −2
Original line number Diff line number Diff line
@@ -3280,8 +3280,7 @@ static int vega10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
			const struct pp_power_state *current_ps)
{
	struct amdgpu_device *adev = hwmgr->adev;
	struct vega10_power_state *vega10_ps =
				cast_phw_vega10_power_state(&request_ps->hardware);
	struct vega10_power_state *vega10_ps;
	uint32_t sclk;
	uint32_t mclk;
	struct PP_Clocks minimum_clocks = {0};
@@ -3299,6 +3298,10 @@ static int vega10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
	uint32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
	uint32_t latency;

	vega10_ps = cast_phw_vega10_power_state(&request_ps->hardware);
	if (!vega10_ps)
		return -EINVAL;

	data->battery_state = (PP_StateUILabel_Battery ==
			request_ps->classification.ui_label);