DragonFlyBSD Kernel Audit
DF-1997 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/dev/drm/amd/amdgpu/amdgpu_gfx.c b/sys/dev/drm/amd/amdgpu/amdgpu_gfx.c
--- a/sys/dev/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/sys/dev/drm/amd/amdgpu/amdgpu_gfx.c
@@ -95,10 +95,13 @@
  *
  * Free a CP scratch register allocated for use by the driver (all asics)
  */
-void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
-{
-	adev->gfx.scratch.free_mask |= 1u << (reg - adev->gfx.scratch.reg_base);
-}
+void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
+{
+	uint32_t bit = reg - adev->gfx.scratch.reg_base;
+
+	if (bit < 32 && bit < adev->gfx.scratch.num_reg)
+		adev->gfx.scratch.free_mask |= 1u << bit;
+}
 
 /**
  * amdgpu_gfx_parse_disable_cu - Parse the disable_cu module parameter