Skip to content

Commit cdb637d

Browse files
srishanmalexdeucher
authored andcommitted
drm/amdgpu: Fix potential out-of-bounds access in 'amdgpu_discovery_reg_base_init()'
The issue arises when the array 'adev->vcn.vcn_config' is accessed before checking if the index 'adev->vcn.num_vcn_inst' is within the bounds of the array. The fix involves moving the bounds check before the array access. This ensures that 'adev->vcn.num_vcn_inst' is within the bounds of the array before it is used as an index. Fixes the below: drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1289 amdgpu_discovery_reg_base_init() error: testing array offset 'adev->vcn.num_vcn_inst' after use. Fixes: a0ccc71 ("drm/amdgpu/discovery: validate VCN and SDMA instances") Cc: Christian König <[email protected]> Cc: Alex Deucher <[email protected]> Signed-off-by: Srinivasan Shanmugam <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 015bae7 commit cdb637d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,11 +1282,10 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
12821282
* 0b10 : encode is disabled
12831283
* 0b01 : decode is disabled
12841284
*/
1285-
adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
1286-
ip->revision & 0xc0;
1287-
ip->revision &= ~0xc0;
12881285
if (adev->vcn.num_vcn_inst <
12891286
AMDGPU_MAX_VCN_INSTANCES) {
1287+
adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
1288+
ip->revision & 0xc0;
12901289
adev->vcn.num_vcn_inst++;
12911290
adev->vcn.inst_mask |=
12921291
(1U << ip->instance_number);
@@ -1297,6 +1296,7 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
12971296
adev->vcn.num_vcn_inst + 1,
12981297
AMDGPU_MAX_VCN_INSTANCES);
12991298
}
1299+
ip->revision &= ~0xc0;
13001300
}
13011301
if (le16_to_cpu(ip->hw_id) == SDMA0_HWID ||
13021302
le16_to_cpu(ip->hw_id) == SDMA1_HWID ||

0 commit comments

Comments
 (0)