Skip to content

Commit a0ccc71

Browse files
committed
drm/amdgpu/discovery: validate VCN and SDMA instances
Validate the VCN and SDMA instances against the driver structure sizes to make sure we don't get into a situation where the firmware reports more instances than the driver supports. Reviewed-by: Guchun Chen <[email protected]> Acked-by: Christian König <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 76818cd commit a0ccc71

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,13 +1130,24 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
11301130
adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
11311131
ip->revision & 0xc0;
11321132
ip->revision &= ~0xc0;
1133-
adev->vcn.num_vcn_inst++;
1133+
if (adev->vcn.num_vcn_inst < AMDGPU_MAX_VCN_INSTANCES)
1134+
adev->vcn.num_vcn_inst++;
1135+
else
1136+
dev_err(adev->dev, "Too many VCN instances: %d vs %d\n",
1137+
adev->vcn.num_vcn_inst + 1,
1138+
AMDGPU_MAX_VCN_INSTANCES);
11341139
}
11351140
if (le16_to_cpu(ip->hw_id) == SDMA0_HWID ||
11361141
le16_to_cpu(ip->hw_id) == SDMA1_HWID ||
11371142
le16_to_cpu(ip->hw_id) == SDMA2_HWID ||
1138-
le16_to_cpu(ip->hw_id) == SDMA3_HWID)
1139-
adev->sdma.num_instances++;
1143+
le16_to_cpu(ip->hw_id) == SDMA3_HWID) {
1144+
if (adev->sdma.num_instances < AMDGPU_MAX_SDMA_INSTANCES)
1145+
adev->sdma.num_instances++;
1146+
else
1147+
dev_err(adev->dev, "Too many SDMA instances: %d vs %d\n",
1148+
adev->sdma.num_instances + 1,
1149+
AMDGPU_MAX_SDMA_INSTANCES);
1150+
}
11401151

11411152
if (le16_to_cpu(ip->hw_id) == UMC_HWID)
11421153
adev->gmc.num_umc++;

0 commit comments

Comments
 (0)