drm/amdgpu/discovery: validate VCN and SDMA instances
Subsystems (2)
Alex Deucher
maintainerPATCH 1/1 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.
Signed-off-by Alex Deucher <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +14 -3
@@ -1137,13 +1137,24 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev) adev->vcn.vcn_config[adev->vcn.num_vcn_inst] = ip->revision &0xc0 ; ip->revision &= ~0xc0 ; - adev->vcn.num_vcn_inst++; +if (adev->vcn.num_vcn_inst <AMDGPU_MAX_VCN_INSTANCES ) + adev->vcn.num_vcn_inst++; +else +dev_err (adev->dev,"Too many VCN instances: %d vs %d\n" , + adev->vcn.num_vcn_inst +1 , +AMDGPU_MAX_VCN_INSTANCES ); }if (le16_to_cpu (ip->hw_id) ==SDMA0_HWID ||le16_to_cpu (ip->hw_id) ==SDMA1_HWID ||le16_to_cpu (ip->hw_id) ==SDMA2_HWID || -le16_to_cpu (ip->hw_id) ==SDMA3_HWID ) - adev->sdma.num_instances++; +le16_to_cpu (ip->hw_id) ==SDMA3_HWID ) { +if (adev->sdma.num_instances <AMDGPU_MAX_SDMA_INSTANCES ) + adev->sdma.num_instances++; +else +dev_err (adev->dev,"Too many SDMA instances: %d vs %d\n" , + adev->sdma.num_instances +1 , +AMDGPU_MAX_SDMA_INSTANCES ); + }if (le16_to_cpu (ip->hw_id) ==UMC_HWID ) adev->gmc.num_umc++;
Signature · 1 line
2.35.3
Reviewed-by Guchun Chen <[email protected]>
Regards,
Guchun
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Tuesday, May 17, 2022 2:17 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH] 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.
Signed-off-by Alex Deucher <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +14 -3
@@ -1137,13 +1137,24 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev) adev->vcn.vcn_config[adev->vcn.num_vcn_inst] = ip->revision &0xc0 ; ip->revision &= ~0xc0 ; - adev->vcn.num_vcn_inst++; +if (adev->vcn.num_vcn_inst <AMDGPU_MAX_VCN_INSTANCES ) + adev->vcn.num_vcn_inst++; +else +dev_err (adev->dev,"Too many VCN instances: %d vs %d\n" , + adev->vcn.num_vcn_inst +1 , +AMDGPU_MAX_VCN_INSTANCES ); }if (le16_to_cpu (ip->hw_id) ==SDMA0_HWID ||le16_to_cpu (ip->hw_id) ==SDMA1_HWID ||le16_to_cpu (ip->hw_id) ==SDMA2_HWID || -le16_to_cpu (ip->hw_id) ==SDMA3_HWID ) - adev->sdma.num_instances++; +le16_to_cpu (ip->hw_id) ==SDMA3_HWID ) { +if (adev->sdma.num_instances <AMDGPU_MAX_SDMA_INSTANCES ) + adev->sdma.num_instances++; +else +dev_err (adev->dev,"Too many SDMA instances: %d vs %d\n" , + adev->sdma.num_instances +1 , +AMDGPU_MAX_SDMA_INSTANCES ); + }if (le16_to_cpu (ip->hw_id) ==UMC_HWID ) adev->gmc.num_umc++;
--
2.35.3