--- a/sys/dev/drm/amd/amdgpu/kv_dpm.c +++ b/sys/dev/drm/amd/amdgpu/kv_dpm.c @@ -162,10 +162,13 @@ static void sumo_construct_vid_mapping_table(struct amdgpu_device *adev, ATOM_AVAILABLE_SCLK_LIST *table) { u32 i, j; - for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) { - if (table[i].ulSupportedSCLK != 0) { + /* usVoltageIndex is an untrusted USHORT from the VBIOS; entries[] only + * has SUMO_MAX_NUMBER_VOLTAGES slots (kv_dpm.h). */ + for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) { + if (table[i].ulSupportedSCLK != 0 && + table[i].usVoltageIndex < SUMO_MAX_NUMBER_VOLTAGES) { vid_mapping_table->entries[table[i].usVoltageIndex].vid_7bit = table[i].usVoltageID; vid_mapping_table->entries[table[i].usVoltageIndex].vid_2bit = table[i].usVoltageIndex; }