Skip to contentSkip to conversation

drm/amd check num of link levels when update pcie param

PATCH In review Lin.Cao 2 participants 2 messages Oct 19, 2023 – Oct 25, 2023

Subsystems (3)
lore
Share & tools
lore

Lin.Cao

author
#0 lore raw

PATCH 1/1 drm/amd check num of link levels when update pcie param

In SR-IOV environment, the value of pcie_table->num_of_link_levels will be 0, and num_of_levels - 1 will cause array index out of bounds

---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c +3 -0
index bcb7ab9d2221..6906b0a7d1d1 100644
@@ -2437,6 +2437,9 @@ int smu_v13_0_update_pcie_parameters(struct smu_context *smu,
 	uint32_t smu_pcie_arg;
 	int ret, i;
 
+	if (!num_of_levels)
+		return 0;
+
 	if (!amdgpu_device_pcie_dynamic_switching_supported()) {
 		if (pcie_table->pcie_gen[num_of_levels - 1] < pcie_gen_cap)
 			pcie_gen_cap = pcie_table->pcie_gen[num_of_levels - 1];
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

Best Regards,
JingWen Chen

Quoted 22 lines · Lin.Cao

In SR-IOV environment, the value of pcie_table->num_of_link_levels will be 0, and num_of_levels - 1 will cause array index out of bounds

---
  drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c +3 -0
index bcb7ab9d2221..6906b0a7d1d1 100644
@@ -2437,6 +2437,9 @@ int smu_v13_0_update_pcie_parameters(struct smu_context *smu,
  	uint32_t smu_pcie_arg;
  	int ret, i;
 
+	if (!num_of_levels)
+		return 0;
+
  	if (!amdgpu_device_pcie_dynamic_switching_supported()) {
  		if (pcie_table->pcie_gen[num_of_levels - 1] < pcie_gen_cap)
  			pcie_gen_cap = pcie_table->pcie_gen[num_of_levels - 1];