mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 20:54:03 +02:00
drm/amd/pm: Validate custom profile parameters
Add helpers to validate custom profile params against negative/out-of-range values. Use the helpers to validate user passed params. Signed-off-by: Lijo Lazar <lijo.lazar@amd.com> Assisted-by: Claude Sonnet (Cursor AI) Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
parent
17ac73b240
commit
921926a12e
|
|
@ -1466,9 +1466,10 @@ static int arcturus_set_power_profile_mode(struct smu_context *smu,
|
|||
return -ENOMEM;
|
||||
}
|
||||
if (custom_params && custom_params_max_idx) {
|
||||
if (custom_params_max_idx != ARCTURUS_CUSTOM_PARAMS_COUNT)
|
||||
return -EINVAL;
|
||||
if (custom_params[0] >= ARCTURUS_CUSTOM_PARAMS_CLOCK_COUNT)
|
||||
if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
|
||||
ARCTURUS_CUSTOM_PARAMS_COUNT) ||
|
||||
!smu_cmn_custom_params_clock_valid(custom_params[0],
|
||||
ARCTURUS_CUSTOM_PARAMS_CLOCK_COUNT))
|
||||
return -EINVAL;
|
||||
idx = custom_params[0] * ARCTURUS_CUSTOM_PARAMS_COUNT;
|
||||
smu->custom_profile_params[idx] = 1;
|
||||
|
|
|
|||
|
|
@ -1843,9 +1843,10 @@ static int navi10_set_power_profile_mode(struct smu_context *smu,
|
|||
return -ENOMEM;
|
||||
}
|
||||
if (custom_params && custom_params_max_idx) {
|
||||
if (custom_params_max_idx != NAVI10_CUSTOM_PARAMS_COUNT)
|
||||
return -EINVAL;
|
||||
if (custom_params[0] >= NAVI10_CUSTOM_PARAMS_CLOCKS_COUNT)
|
||||
if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
|
||||
NAVI10_CUSTOM_PARAMS_COUNT) ||
|
||||
!smu_cmn_custom_params_clock_valid(custom_params[0],
|
||||
NAVI10_CUSTOM_PARAMS_CLOCKS_COUNT))
|
||||
return -EINVAL;
|
||||
idx = custom_params[0] * NAVI10_CUSTOM_PARAMS_COUNT;
|
||||
smu->custom_profile_params[idx] = 1;
|
||||
|
|
|
|||
|
|
@ -1755,9 +1755,10 @@ static int sienna_cichlid_set_power_profile_mode(struct smu_context *smu,
|
|||
return -ENOMEM;
|
||||
}
|
||||
if (custom_params && custom_params_max_idx) {
|
||||
if (custom_params_max_idx != SIENNA_CICHLID_CUSTOM_PARAMS_COUNT)
|
||||
return -EINVAL;
|
||||
if (custom_params[0] >= SIENNA_CICHLID_CUSTOM_PARAMS_CLOCK_COUNT)
|
||||
if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
|
||||
SIENNA_CICHLID_CUSTOM_PARAMS_COUNT) ||
|
||||
!smu_cmn_custom_params_clock_valid(custom_params[0],
|
||||
SIENNA_CICHLID_CUSTOM_PARAMS_CLOCK_COUNT))
|
||||
return -EINVAL;
|
||||
idx = custom_params[0] * SIENNA_CICHLID_CUSTOM_PARAMS_COUNT;
|
||||
smu->custom_profile_params[idx] = 1;
|
||||
|
|
|
|||
|
|
@ -2616,9 +2616,10 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
|
|||
return -ENOMEM;
|
||||
}
|
||||
if (custom_params && custom_params_max_idx) {
|
||||
if (custom_params_max_idx != SMU_13_0_0_CUSTOM_PARAMS_COUNT)
|
||||
return -EINVAL;
|
||||
if (custom_params[0] >= SMU_13_0_0_CUSTOM_PARAMS_CLOCK_COUNT)
|
||||
if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
|
||||
SMU_13_0_0_CUSTOM_PARAMS_COUNT) ||
|
||||
!smu_cmn_custom_params_clock_valid(custom_params[0],
|
||||
SMU_13_0_0_CUSTOM_PARAMS_CLOCK_COUNT))
|
||||
return -EINVAL;
|
||||
idx = custom_params[0] * SMU_13_0_0_CUSTOM_PARAMS_COUNT;
|
||||
smu->custom_profile_params[idx] = 1;
|
||||
|
|
|
|||
|
|
@ -2573,9 +2573,10 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu,
|
|||
return -ENOMEM;
|
||||
}
|
||||
if (custom_params && custom_params_max_idx) {
|
||||
if (custom_params_max_idx != SMU_13_0_7_CUSTOM_PARAMS_COUNT)
|
||||
return -EINVAL;
|
||||
if (custom_params[0] >= SMU_13_0_7_CUSTOM_PARAMS_CLOCK_COUNT)
|
||||
if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
|
||||
SMU_13_0_7_CUSTOM_PARAMS_COUNT) ||
|
||||
!smu_cmn_custom_params_clock_valid(custom_params[0],
|
||||
SMU_13_0_7_CUSTOM_PARAMS_CLOCK_COUNT))
|
||||
return -EINVAL;
|
||||
idx = custom_params[0] * SMU_13_0_7_CUSTOM_PARAMS_COUNT;
|
||||
smu->custom_profile_params[idx] = 1;
|
||||
|
|
|
|||
|
|
@ -1828,9 +1828,10 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
|
|||
return -ENOMEM;
|
||||
}
|
||||
if (custom_params && custom_params_max_idx) {
|
||||
if (custom_params_max_idx != SMU_14_0_2_CUSTOM_PARAMS_COUNT)
|
||||
return -EINVAL;
|
||||
if (custom_params[0] >= SMU_14_0_2_CUSTOM_PARAMS_CLOCK_COUNT)
|
||||
if (!smu_cmn_custom_params_count_valid(custom_params_max_idx,
|
||||
SMU_14_0_2_CUSTOM_PARAMS_COUNT) ||
|
||||
!smu_cmn_custom_params_clock_valid(custom_params[0],
|
||||
SMU_14_0_2_CUSTOM_PARAMS_CLOCK_COUNT))
|
||||
return -EINVAL;
|
||||
idx = custom_params[0] * SMU_14_0_2_CUSTOM_PARAMS_COUNT;
|
||||
smu->custom_profile_params[idx] = 1;
|
||||
|
|
|
|||
|
|
@ -113,6 +113,16 @@ static inline int pcie_gen_to_speed(uint32_t gen)
|
|||
return ((gen == 0) ? link_speed[0] : link_speed[gen - 1]);
|
||||
}
|
||||
|
||||
static inline bool smu_cmn_custom_params_count_valid(u32 max_idx, u32 params_count)
|
||||
{
|
||||
return max_idx == params_count;
|
||||
}
|
||||
|
||||
static inline bool smu_cmn_custom_params_clock_valid(long clock_idx, long clock_count)
|
||||
{
|
||||
return clock_idx >= 0 && clock_idx < clock_count;
|
||||
}
|
||||
|
||||
int smu_cmn_send_smc_msg_with_param(struct smu_context *smu,
|
||||
enum smu_message_type msg,
|
||||
uint32_t param,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user