Skip to contentSkip to conversation

drm/amdgpu: fix UBSAN warning in kv_dpm.c

PATCH In review Alex Deucher 2 participants 4 messages Jun 14, 2024

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/2 drm/amdgpu: fix UBSAN warning in kv_dpm.c

Adds bounds check for sumo_vid_mapping_entry.

---
 drivers/gpu/drm/amd/pm/legacy-dpm/kv_dpm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/pm/legacy-dpm/kv_dpm.c +2 -0
index 6bb42d04b247..e8b6989a40f3 100644
@@ -164,6 +164,8 @@ static void sumo_construct_vid_mapping_table(struct amdgpu_device *adev,
 
 	for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) {
 		if (table[i].ulSupportedSCLK != 0) {
+			if (table[i].usVoltageIndex >= SUMO_MAX_NUMBER_VOLTAGES)
+				continue;
 			vid_mapping_table->entries[table[i].usVoltageIndex].vid_7bit =
 				table[i].usVoltageID;
 			vid_mapping_table->entries[table[i].usVoltageIndex].vid_2bit =
Signature · 1 line
2.45.1
author maintainer
#1 lore raw

PATCH 2/2 drm/radeon: fix UBSAN warning in kv_dpm.c

Adds bounds check for sumo_vid_mapping_entry.

---
 drivers/gpu/drm/radeon/sumo_dpm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/radeon/sumo_dpm.c +2 -0
index 21d27e6235f3..b11f7c5bbcbe 100644
@@ -1619,6 +1619,8 @@ void sumo_construct_vid_mapping_table(struct radeon_device *rdev,
 
 	for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) {
 		if (table[i].ulSupportedSCLK != 0) {
+			if (table[i].usVoltageIndex >= SUMO_MAX_NUMBER_VOLTAGES)
+				continue;
 			vid_mapping_table->entries[table[i].usVoltageIndex].vid_7bit =
 				table[i].usVoltageID;
 			vid_mapping_table->entries[table[i].usVoltageIndex].vid_2bit =
Signature · 1 line
2.45.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/radeon: fix UBSAN warning in kv_dpm.c

Quoted 3 lines · Alex Deucher

Adds bounds check for sumo_vid_mapping_entry.

Quoted 17 lines
---
  drivers/gpu/drm/radeon/sumo_dpm.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/radeon/sumo_dpm.c +2 -0
index 21d27e6235f3..b11f7c5bbcbe 100644
@@ -1619,6 +1619,8 @@ void sumo_construct_vid_mapping_table(struct radeon_device *rdev,
 
  	for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) {
  		if (table[i].ulSupportedSCLK != 0) {
+			if (table[i].usVoltageIndex >= SUMO_MAX_NUMBER_VOLTAGES)
+				continue;
  			vid_mapping_table->entries[table[i].usVoltageIndex].vid_7bit =
  				table[i].usVoltageID;
  			vid_mapping_table->entries[table[i].usVoltageIndex].vid_2bit =
Reviewed-by on v1 1/2
#3 lore raw
In reply to Alex Deucher
Quoted 4 lines · Alex Deucher

Adds bounds check for sumo_vid_mapping_entry.

Quoted 17 lines
---
  drivers/gpu/drm/amd/pm/legacy-dpm/kv_dpm.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/pm/legacy-dpm/kv_dpm.c +2 -0
index 6bb42d04b247..e8b6989a40f3 100644
@@ -164,6 +164,8 @@ static void sumo_construct_vid_mapping_table(struct amdgpu_device *adev,
 
  	for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++) {
  		if (table[i].ulSupportedSCLK != 0) {
+			if (table[i].usVoltageIndex >= SUMO_MAX_NUMBER_VOLTAGES)
+				continue;
  			vid_mapping_table->entries[table[i].usVoltageIndex].vid_7bit =
  				table[i].usVoltageID;
  			vid_mapping_table->entries[table[i].usVoltageIndex].vid_2bit =