Skip to contentSkip to conversation

Fix unintentional integer overflow

PATCH Applied Advait Dhamorikar 4 participants 4 messages Oct 3, 2024 – Oct 4, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Fix unintentional integer overflow

Fix shift-count-overflow in JPEG instance multiplication. The expression's value may not be what the programmer intended, because the expression is evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")

---
V1 -> V2: addressed review comments

 drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..b6f0435f56ba 100644
@@ -357,7 +357,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_set(void *data, u64 val)
 	if (!adev)
 		return -ENODEV;
 
-	mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
+	mask = ((uint64_t)1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
 	if ((val & mask) == 0)
 		return -EINVAL;
 
Signature · 1 line
2.34.1
#1 lore raw

The patch is Reviewed-by: Sathishkumar S <[email protected]>

Regards,
Sathish

Quoted 26 lines · Advait Dhamorikar

Fix shift-count-overflow in JPEG instance multiplication. The expression's value may not be what the programmer intended, because the expression is evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")

---
V1 -> V2: addressed review comments

  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..b6f0435f56ba 100644
@@ -357,7 +357,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_set(void *data, u64 val)
  	if (!adev)
  		return -ENODEV;
 
-	mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
+	mask = ((uint64_t)1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
  	if ((val & mask) == 0)
  		return -EINVAL;
 
Applied
#2 lore raw

Applied. Thanks!

Quoted 35 lines · Sathishkumar

The patch is Reviewed-by: Sathishkumar S <[email protected]>

Regards,
Sathish

Quoted 26 lines · Advait Dhamorikar

Fix shift-count-overflow in JPEG instance multiplication. The expression's value may not be what the programmer intended, because the expression is evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")

---
V1 -> V2: addressed review comments

  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..b6f0435f56ba 100644
@@ -357,7 +357,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_set(void *data, u64 val)
      if (!adev)
              return -ENODEV;
 
-     mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
+     mask = ((uint64_t)1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
      if ((val & mask) == 0)
              return -EINVAL;
 
#3 lore raw
In reply to Advait Dhamorikar
Quoted 18 lines · Advait Dhamorikar

Fix shift-count-overflow in JPEG instance multiplication. The expression's value may not be what the programmer intended, because the expression is evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")

---
V1 -> V2: addressed review comments

 drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 95e2796919fc..b6f0435f56ba 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c static int amdgpu_debugfs_jpeg_sched_mask_set(void *data, u64 val) · line 360

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
@@ -357,7 +357,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_set(void *data, u64 val)
 	if (!adev)
 		return -ENODEV;
 
-	mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;
+	mask = ((uint64_t)1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1;

Using 1ULL here is more legible.

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
 	if ((val & mask) == 0)
 		return -EINVAL;