drm/radeon: Fix scratch register leak in IB test.
Subsystems (2)
PATCH 1/1 drm/radeon: Fix scratch register leak in IB test.
From: Michel Dänzer <[email protected]>
Restructure the code to jump out via labels instead of directly returning early. Also make error reporting consistent across all hardware generations.
Signed-off-by Michel Dänzer <[email protected]>
Reviewed-by Simon Kitching <[email protected]>
Reviewed-by Christian König <[email protected]>
--- drivers/gpu/drm/radeon/r100.c | 15 +++++++++------ drivers/gpu/drm/radeon/r600.c | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-)
drivers/gpu/drm/radeon/r100.c +9 -6
@@ -3818,7 +3818,8 @@ int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)WREG32 (scratch,0xCAFEDEAD ); r =radeon_ib_get (rdev,RADEON_RING_TYPE_GFX_INDEX , &ib,256 );if (r) { -return r; +DRM_ERROR ("radeon: failed to get ib (%d).\n" , r); + goto free_scratch; } ib.ptr[0 ] =PACKET0 (scratch,0 ); ib.ptr[1 ] =0xDEADBEEF ;
@@ -3831,13 +3832,13 @@ int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) ib.length_dw =8 ; r =radeon_ib_schedule (rdev, &ib,NULL );if (r) { -radeon_scratch_free (rdev, scratch); -radeon_ib_free (rdev, &ib); -return r; +DRM_ERROR ("radeon: failed to schedule ib (%d).\n" , r); + goto free_ib; } r =radeon_fence_wait (ib.fence, false);if (r) { -return r; +DRM_ERROR ("radeon: fence wait failed (%d).\n" , r); + goto free_ib; }for (i =0 ; i < rdev->usec_timeout; i++) { tmp =RREG32 (scratch);
@@ -3853,8 +3854,10 @@ int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) scratch, tmp); r = -EINVAL ; } -radeon_scratch_free (rdev, scratch); +free_ib:radeon_ib_free (rdev, &ib); +free_scratch: +radeon_scratch_free (rdev, scratch);return r; }
drivers/gpu/drm/radeon/r600.c +6 -6
@@ -2638,7 +2638,7 @@ int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) r =radeon_ib_get (rdev, ring->idx, &ib,256 );if (r) {DRM_ERROR ("radeon: failed to get ib (%d).\n" , r); -return r; + goto free_scratch; } ib.ptr[0 ] =PACKET3 (PACKET3_SET_CONFIG_REG ,1 ); ib.ptr[1 ] = ((scratch -PACKET3_SET_CONFIG_REG_OFFSET ) >>2 );
@@ -2646,15 +2646,13 @@ int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) ib.length_dw =3 ; r =radeon_ib_schedule (rdev, &ib,NULL );if (r) { -radeon_scratch_free (rdev, scratch); -radeon_ib_free (rdev, &ib);DRM_ERROR ("radeon: failed to schedule ib (%d).\n" , r); -return r; + goto free_ib; } r =radeon_fence_wait (ib.fence, false);if (r) {DRM_ERROR ("radeon: fence wait failed (%d).\n" , r); -return r; + goto free_ib; }for (i =0 ; i < rdev->usec_timeout; i++) { tmp =RREG32 (scratch);
@@ -2669,8 +2667,10 @@ int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) scratch, tmp); r = -EINVAL ; } -radeon_scratch_free (rdev, scratch); +free_ib:radeon_ib_free (rdev, &ib); +free_scratch: +radeon_scratch_free (rdev, scratch);return r; }
Signature · 6 lines
1.7.10.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
Restructure the code to jump out via labels instead of directly returning early. Also make error reporting consistent across all hardware generations.
Signed-off-by Michel Dänzer <[email protected]>Reviewed-by Simon Kitching <[email protected]>Reviewed-by Christian König <[email protected]>
Added to my -next tree.
Alex
Quoted 99 lines
--- drivers/gpu/drm/radeon/r100.c | 15 +++++++++------ drivers/gpu/drm/radeon/r600.c | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-)drivers/gpu/drm/radeon/r100.c +9
-6@@ -3818,7 +3818,8 @@ int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)WREG32 (scratch,0xCAFEDEAD ); r =radeon_ib_get (rdev,RADEON_RING_TYPE_GFX_INDEX , &ib,256 );if (r) { -return r; +DRM_ERROR ("radeon: failed to get ib (%d).\n" , r); + goto free_scratch; } ib.ptr[0 ] =PACKET0 (scratch,0 ); ib.ptr[1 ] =0xDEADBEEF ;@@ -3831,13 +3832,13 @@ int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) ib.length_dw =8 ; r =radeon_ib_schedule (rdev, &ib,NULL );if (r) { -radeon_scratch_free (rdev, scratch); -radeon_ib_free (rdev, &ib); -return r; +DRM_ERROR ("radeon: failed to schedule ib (%d).\n" , r); + goto free_ib; } r =radeon_fence_wait (ib.fence, false);if (r) { -return r; +DRM_ERROR ("radeon: fence wait failed (%d).\n" , r); + goto free_ib; }for (i =0 ; i < rdev->usec_timeout; i++) { tmp =RREG32 (scratch);@@ -3853,8 +3854,10 @@ int r100_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) scratch, tmp); r = -EINVAL ; } -radeon_scratch_free (rdev, scratch); +free_ib:radeon_ib_free (rdev, &ib); +free_scratch: +radeon_scratch_free (rdev, scratch);return r; }drivers/gpu/drm/radeon/r600.c +6
-7@@ -2638,7 +2638,7 @@ int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) r =radeon_ib_get (rdev, ring->idx, &ib,256 );if (r) {DRM_ERROR ("radeon: failed to get ib (%d).\n" , r); -return r; + goto free_scratch; } ib.ptr[0 ] =PACKET3 (PACKET3_SET_CONFIG_REG ,1 ); ib.ptr[1 ] = ((scratch -PACKET3_SET_CONFIG_REG_OFFSET ) >>2 );@@ -2646,15 +2646,13 @@ int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) ib.length_dw =3 ; r =radeon_ib_schedule (rdev, &ib,NULL );if (r) { -radeon_scratch_free (rdev, scratch); -radeon_ib_free (rdev, &ib);DRM_ERROR ("radeon: failed to schedule ib (%d).\n" , r); -return r; + goto free_ib; } r =radeon_fence_wait (ib.fence, false);if (r) {DRM_ERROR ("radeon: fence wait failed (%d).\n" , r); -return r; + goto free_ib; }for (i =0 ; i < rdev->usec_timeout; i++) { tmp =RREG32 (scratch);@@ -2669,8 +2667,10 @@ int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring) scratch, tmp); r = -EINVAL ; } -radeon_scratch_free (rdev, scratch); +free_ib:radeon_ib_free (rdev, &ib); +free_scratch: +radeon_scratch_free (rdev, scratch);return r; } --1.7.10.4
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel