Skip to contentSkip to conversation

drm/amdgpu: fix double reference dropping

PATCH Applied Pan Bian 3 participants 3 messages Nov 6, 2019

Subsystems (2)
lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH v2 1/1 drm/amdgpu: fix double reference dropping

The reference to object fence is dropped at the end of the loop. However, it is dropped again outside the loop. The reference can be dropped immediately after calling dma_fence_wait() in the loop and thus the dropping operation outside the loop can be removed.

---
v2: fix the bug in a more concise way

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +2 -4
index 649e68c4479b..d1495e1c9289 100644
@@ -33,7 +33,7 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
 {
 	unsigned long start_jiffies;
 	unsigned long end_jiffies;
-	struct dma_fence *fence = NULL;
+	struct dma_fence *fence;
 	int i, r;
 
 	start_jiffies = jiffies;
@@ -44,16 +44,14 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
 		if (r)
 			goto exit_do_move;
 		r = dma_fence_wait(fence, false);
+		dma_fence_put(fence);
 		if (r)
 			goto exit_do_move;
-		dma_fence_put(fence);
 	}
 	end_jiffies = jiffies;
 	r = jiffies_to_msecs(end_jiffies - start_jiffies);
 
 exit_do_move:
-	if (fence)
-		dma_fence_put(fence);
 	return r;
 }
 
Signature · 1 line
2.7.4
maintainer Reviewed-by on v2 1/1
#1 lore raw

Am 06.11.19 um 12:35 schrieb Pan Bian:

Quoted 6 lines

The reference to object fence is dropped at the end of the loop. However, it is dropped again outside the loop. The reference can be dropped immediately after calling dma_fence_wait() in the loop and thus the dropping operation outside the loop can be removed.

Quoted 27 lines

---
v2: fix the bug in a more concise way

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +2 -2
index 649e68c4479b..d1495e1c9289 100644
@@ -33,7 +33,7 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
  {
  	unsigned long start_jiffies;
  	unsigned long end_jiffies;
-	struct dma_fence *fence = NULL;
+	struct dma_fence *fence;
  	int i, r;
 
  	start_jiffies = jiffies;
@@ -44,16 +44,14 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
  		if (r)
  			goto exit_do_move;
  		r = dma_fence_wait(fence, false);
+		dma_fence_put(fence);
  		if (r)
  			goto exit_do_move;
-		dma_fence_put(fence);

drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size, · line 57

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +0 -2
  	}
  	end_jiffies = jiffies;
  	r = jiffies_to_msecs(end_jiffies - start_jiffies);
 
  exit_do_move:
-	if (fence)
-		dma_fence_put(fence);
  	return r;
  }
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Applied
#2 lore raw
Quoted 11 lines · Christian

Am 06.11.19 um 12:35 schrieb Pan Bian:

Quoted 6 lines

The reference to object fence is dropped at the end of the loop. However, it is dropped again outside the loop. The reference can be dropped immediately after calling dma_fence_wait() in the loop and thus the dropping operation outside the loop can be removed.

Applied. thanks!

Alex

Quoted 31 lines
Quoted 31 lines

---
v2: fix the bug in a more concise way

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +2 -2
index 649e68c4479b..d1495e1c9289 100644
@@ -33,7 +33,7 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
  {
      unsigned long start_jiffies;
      unsigned long end_jiffies;
-     struct dma_fence *fence = NULL;
+     struct dma_fence *fence;
      int i, r;
 
      start_jiffies = jiffies;
@@ -44,16 +44,14 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
              if (r)
                      goto exit_do_move;
              r = dma_fence_wait(fence, false);
+             dma_fence_put(fence);
              if (r)
                      goto exit_do_move;
-             dma_fence_put(fence);
      }
      end_jiffies = jiffies;
      r = jiffies_to_msecs(end_jiffies - start_jiffies);
 
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size, · line 57

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +0 -2
  exit_do_move:
-     if (fence)
-             dma_fence_put(fence);
      return r;
  }
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx