Skip to content

Commit 34c4eb7

Browse files
KarolPWralexdeucher
authored andcommitted
drm/amdgpu: Fix potential integer overflow in scheduler mask calculations
The use of 1 << i in scheduler mask calculations can result in an unintentional integer overflow due to the expression being evaluated as a 32-bit signed integer. This patch replaces 1 << i with 1ULL << i to ensure the operation is performed as a 64-bit unsigned integer, preventing overflow Discovered in coverity scan, CID 1636393, 1636175, 1636007, 1635853 Fixes: c5c63d9 ("drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs") Signed-off-by: Karol Przybylski <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 8f2cd10 commit 34c4eb7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,7 @@ static int amdgpu_debugfs_gfx_sched_mask_set(void *data, u64 val)
21242124
if (!adev)
21252125
return -ENODEV;
21262126

2127-
mask = (1 << adev->gfx.num_gfx_rings) - 1;
2127+
mask = (1ULL << adev->gfx.num_gfx_rings) - 1;
21282128
if ((val & mask) == 0)
21292129
return -EINVAL;
21302130

@@ -2152,7 +2152,7 @@ static int amdgpu_debugfs_gfx_sched_mask_get(void *data, u64 *val)
21522152
for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
21532153
ring = &adev->gfx.gfx_ring[i];
21542154
if (ring->sched.ready)
2155-
mask |= 1 << i;
2155+
mask |= 1ULL << i;
21562156
}
21572157

21582158
*val = mask;
@@ -2194,7 +2194,7 @@ static int amdgpu_debugfs_compute_sched_mask_set(void *data, u64 val)
21942194
if (!adev)
21952195
return -ENODEV;
21962196

2197-
mask = (1 << adev->gfx.num_compute_rings) - 1;
2197+
mask = (1ULL << adev->gfx.num_compute_rings) - 1;
21982198
if ((val & mask) == 0)
21992199
return -EINVAL;
22002200

@@ -2223,7 +2223,7 @@ static int amdgpu_debugfs_compute_sched_mask_get(void *data, u64 *val)
22232223
for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
22242224
ring = &adev->gfx.compute_ring[i];
22252225
if (ring->sched.ready)
2226-
mask |= 1 << i;
2226+
mask |= 1ULL << i;
22272227
}
22282228

22292229
*val = mask;

0 commit comments

Comments
 (0)