drm/amd/pm: Fix the null pointer dereference for vega10_hwmgr
Subsystems (3)
PATCH v3 1/1 drm/amd/pm: Fix the null pointer dereference for vega10_hwmgr
Check return value and conduct null pointer handling to avoid null pointer dereference.
--- .../drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +25 -4
@@ -3439,13 +3439,17 @@ static int vega10_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, coconst struct vega10_power_state *vega10_ps =cast_const_phw_vega10_power_state (states->pnew_state);struct vega10_single_dpm_table *sclk_table = &(data->dpm_table.gfx_table); -uint32_t sclk = vega10_ps->performance_levels - [vega10_ps->performance_level_count -1 ].gfx_clock;struct vega10_single_dpm_table *mclk_table = &(data->dpm_table.mem_table); -uint32_t mclk = vega10_ps->performance_levels - [vega10_ps->performance_level_count -1 ].mem_clock; +uint32_t sclk, mclk;uint32_t i; +if (vega10_ps ==NULL ) +return -EINVAL ; + sclk = vega10_ps->performance_levels + [vega10_ps->performance_level_count -1 ].gfx_clock; + mclk = vega10_ps->performance_levels + [vega10_ps->performance_level_count -1 ].mem_clock; +for (i =0 ; i < sclk_table->count; i++) {if (sclk == sclk_table->dpm_levels[i].value)break ;
@@ -3752,6 +3756,9 @@ static int vega10_generate_dpm_level_enable_mask(cast_const_phw_vega10_power_state (states->pnew_state);int i; +if (vega10_ps ==NULL ) +return -EINVAL ; +PP_ASSERT_WITH_CODE (!vega10_trim_dpm_states (hwmgr, vega10_ps),"Attempt to Trim DPM States Failed!" , return -1 );
@@ -5035,6 +5042,8 @@ static int vega10_check_states_equal(struct pp_hwmgr *hwmgr, vega10_psa =cast_const_phw_vega10_power_state (pstate1); vega10_psb =cast_const_phw_vega10_power_state (pstate2); +if (vega10_psa ==NULL || vega10_psb ==NULL ) +return -EINVAL ;/* If the two states don't even have the same number of performance levels * they cannot be the same state.
@@ -5168,6 +5177,8 @@ static int vega10_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)return -EINVAL ; vega10_ps =cast_phw_vega10_power_state (&ps->hardware); +if (vega10_ps ==NULL ) +return -EINVAL ; vega10_ps->performance_levels [vega10_ps->performance_level_count - 1].gfx_clock =
@@ -5219,6 +5230,8 @@ static int vega10_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)return -EINVAL ; vega10_ps =cast_phw_vega10_power_state (&ps->hardware); +if (vega10_ps ==NULL ) +return -EINVAL ; vega10_ps->performance_levels [vega10_ps->performance_level_count - 1].mem_clock =
@@ -5460,6 +5473,9 @@ static void vega10_odn_update_power_state(struct pp_hwmgr *hwmgr)return ; vega10_ps =cast_phw_vega10_power_state (&ps->hardware); +if (vega10_ps ==NULL ) +return ; + max_level = vega10_ps->performance_level_count -1 ; if (vega10_ps->performance_levels[max_level].gfx_clock !=
@@ -5482,6 +5498,9 @@ static void vega10_odn_update_power_state(struct pp_hwmgr *hwmgr) ps = (struct pp_power_state *)((unsigned long )(hwmgr->ps) + hwmgr->ps_size * (hwmgr->num_ps -1 )); vega10_ps =cast_phw_vega10_power_state (&ps->hardware); +if (vega10_ps ==NULL ) +return ; + max_level = vega10_ps->performance_level_count -1 ; if (vega10_ps->performance_levels[max_level].gfx_clock !=
@@ -5672,6 +5691,8 @@ static int vega10_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_return -EINVAL ; vega10_ps =cast_const_phw_vega10_power_state (state); +if (vega10_ps ==NULL ) +return -EINVAL ; i = index > vega10_ps->performance_level_count -1 ? vega10_ps->performance_level_count -1 : index;
Signature · 1 line
2.34.1
[Public]
This patch is,
Quoted 124 lines
-----Original Message-----
From: Bob Zhou <[email protected]>
Sent: Friday, May 31, 2024 3:01 PM
To: [email protected]; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, Bob <[email protected]>
Subject: [PATCH v3] drm/amd/pm: Fix the null pointer dereference forvega10_hwmgrCheck return value and conduct null pointer handling to avoid null pointer dereference.
Signed-off-by Bob Zhou <[email protected]>--- .../drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +0
-0@@ -3439,13 +3439,17 @@ static intvega10_find_dpm_states_clocks_in_dpm_table(struct
pp_hwmgr*hwmgr, co
const structvega10_power_state*vega10_ps=
cast_const_phw_vega10_power_state(states->pnew_state);
structvega10_single_dpm_table*sclk_table=
&(data->dpm_table.gfx_table);drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +0
-2-uint32_t sclk = vega10_ps->performance_levels - [vega10_ps->performance_level_count -1 ].gfx_clock; struct vega10_single_dpm_table *mclk_table =&(data->dpm_table.mem_table);
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +13
-2-uint32_t mclk = vega10_ps->performance_levels - [vega10_ps->performance_level_count -1 ].mem_clock; +uint32_t sclk, mclk;uint32_t i; +if (vega10_ps ==NULL ) +return -EINVAL ; + sclk = vega10_ps->performance_levels + [vega10_ps->performance_level_count -1 ].gfx_clock; + mclk = vega10_ps->performance_levels + [vega10_ps->performance_level_count -1 ].mem_clock; +for (i =0 ; i < sclk_table->count; i++) {if (sclk == sclk_table->dpm_levels[i].value)break ;@@ -3752,6 +3756,9 @@ static int vega10_generate_dpm_level_enable_mask(cast_const_phw_vega10_power_state (states->pnew_state);int i; +if (vega10_ps ==NULL ) +return -EINVAL ; +PP_ASSERT_WITH_CODE (!vega10_trim_dpm_states (hwmgr, vega10_ps),"Attempt to Trim DPM States Failed!" , return -1 );@@ -5035,6 +5042,8 @@ static int vega10_check_states_equal(structpp_hwmgr *hwmgr, vega10_psa =cast_const_phw_vega10_power_state (pstate1); vega10_psb =cast_const_phw_vega10_power_state (pstate2); +if (vega10_psa ==NULL || vega10_psb ==NULL ) +return -EINVAL ;/* If the two states don't even have the same number of performance levels * they cannot be the same state.
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +2
-0@@ -5168,6 +5177,8 @@ static int vega10_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)return -EINVAL ; vega10_ps =cast_phw_vega10_power_state (&ps->hardware); +if (vega10_ps ==NULL ) +return -EINVAL ; vega10_ps->performance_levels[vega10_ps->performance_level_count - 1].gfx_clock = @@ -5219,6 +5230,8 @@ static int vega10_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value) return -EINVAL; vega10_ps = cast_phw_vega10_power_state(&ps->hardware);drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +3
-0+if (vega10_ps ==NULL ) +return -EINVAL ; vega10_ps->performance_levels [vega10_ps->performance_level_count - 1].mem_clock = @@ -5460,6 +5473,9 @@ static void vega10_odn_update_power_state(struct pp_hwmgr*hwmgr)
return; vega10_ps = cast_phw_vega10_power_state(&ps->hardware);drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +4
-0+if (vega10_ps ==NULL ) +return ; + max_level = vega10_ps->performance_level_count -1 ; if (vega10_ps->performance_levels[max_level].gfx_clock != @@ -5482,6 +5498,9 @@ static void vega10_odn_update_power_state(struct pp_hwmgr*hwmgr)
ps = (struct pp_power_state *)((unsigned long)(hwmgr->ps) + hwmgr->ps_size * (hwmgr->num_ps - 1)); vega10_ps = cast_phw_vega10_power_state(&ps->hardware);drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +4
-0+if (vega10_ps ==NULL ) +return ; + max_level = vega10_ps->performance_level_count -1 ; if (vega10_ps->performance_levels[max_level].gfx_clock != @@ -5672,6 +5691,8 @@ static int vega10_get_performance_level(struct pp_hwmgr*hwmgr, const struct
pp_return -EINVAL; vega10_ps = cast_const_phw_vega10_power_state(state);drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c +2
-1+if (vega10_ps ==NULL ) +return -EINVAL ; i = index > vega10_ps->performance_level_count -1 ? vega10_ps->performance_level_count -1 : index; --2.34.1