drm/amdgpu: fix memory leak in wait_all_fence
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix memory leak in wait_all_fence
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +19 -6
@@ -1216,22 +1216,28 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev, struct drm_amdgpu_fence *fences) {uint32_t fence_count = wait->in.fence_count; +struct fence **array;unsigned int i;long r =1 ; + array =kcalloc (fence_count,sizeof (struct fence *),GFP_KERNEL ); + +if (array ==NULL ) +return -ENOMEM ;for (i =0 ; i < fence_count; i++) {struct fence *fence;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout_ns); fence =amdgpu_cs_get_fence (adev, filp, &fences[i]); -if (IS_ERR (fence)) -return PTR_ERR (fence); -else if (!fence) +if (IS_ERR (fence)) { + r =PTR_ERR (fence); + goto err; + }else if (!fence)continue ; - + array[i] = fence; r =kcl_fence_wait_timeout (fence, true, timeout);if (r <0 ) -return r; + goto err;if (r ==0 )break ;
@@ -1240,7 +1246,14 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,memset (wait,0 ,sizeof (*wait)); wait->out.status = (r >0 ); -return 0 ; + r =0 ; + +err: +for (i =0 ; i < fence_count; i++) +fence_put (array[i]); +kfree (array); + +return r; }/**
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1491536178-5978-1-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
Wang, Ken
Reviewed-by Ken Wang________________________________
发件人: amd-gfx <[email protected]> 代表 Chunming Zhou <[email protected]> 发送时间: 2017年4月7日 11:36:18
收件人: [email protected]; Wang, Ken
抄送: Zhou, David(ChunMing)
主题: [PATCH] drm/amdgpu: fix memory leak in wait_all_fence
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +19 -6
@@ -1216,22 +1216,28 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev, struct drm_amdgpu_fence *fences) {uint32_t fence_count = wait->in.fence_count; +struct fence **array;unsigned int i;long r =1 ; + array =kcalloc (fence_count,sizeof (struct fence *),GFP_KERNEL ); + +if (array ==NULL ) +return -ENOMEM ;for (i =0 ; i < fence_count; i++) {struct fence *fence;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout_ns); fence =amdgpu_cs_get_fence (adev, filp, &fences[i]); -if (IS_ERR (fence)) -return PTR_ERR (fence); -else if (!fence) +if (IS_ERR (fence)) { + r =PTR_ERR (fence); + goto err; + }else if (!fence)continue ; - + array[i] = fence; r =kcl_fence_wait_timeout (fence, true, timeout);if (r <0 ) -return r; + goto err;if (r ==0 )break ;
@@ -1240,7 +1246,14 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,memset (wait,0 ,sizeof (*wait)); wait->out.status = (r >0 ); -return 0 ; + r =0 ; + +err: +for (i =0 ; i < fence_count; i++) +fence_put (array[i]); +kfree (array); + +return r; }/**
--
1.9.1
_______________________________________________
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
Christian König
NAKAm 07.04.2017 um 05:36 schrieb Chunming Zhou:
Quoted 2 lines
Change-Id Ib3e271e00e49f10152c1b3eace981a6bf78820deSigned-off-by Chunming Zhou <[email protected]>
NAK, that will allocate an array for the fence again, which we wanted to avoid.
We should just drop the fence reference directly after waiting for it.
Regards,
Christian.
Quoted 48 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +12
-6@@ -1216,22 +1216,28 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev, struct drm_amdgpu_fence *fences) {uint32_t fence_count = wait->in.fence_count; +struct fence **array;unsigned int i;long r =1 ; + array =kcalloc (fence_count,sizeof (struct fence *),GFP_KERNEL ); + +if (array ==NULL ) +return -ENOMEM ;for (i =0 ; i < fence_count; i++) {struct fence *fence;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout_ns); fence =amdgpu_cs_get_fence (adev, filp, &fences[i]); -if (IS_ERR (fence)) -return PTR_ERR (fence); -else if (!fence) +if (IS_ERR (fence)) { + r =PTR_ERR (fence); + goto err; + }else if (!fence)continue ; - + array[i] = fence; r =kcl_fence_wait_timeout (fence, true, timeout);if (r <0 ) -return r; + goto err;if (r ==0 )break ;@@ -1240,7 +1246,14 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,memset (wait,0 ,sizeof (*wait)); wait->out.status = (r >0 ); -return 0 ; + r =0 ;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev, · line 1259
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +7
-0+ +err: +for (i =0 ; i < fence_count; i++) +fence_put (array[i]); +kfree (array); + +return r; }/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 058491a9-73a6-eddf-73fb-aaac066f9b3e-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 5 lines · Christian König
Am 07.04.2017 um 05:36 schrieb Chunming Zhou:
Quoted 2 lines
Change-Id Ib3e271e00e49f10152c1b3eace981a6bf78820deSigned-off-by Chunming Zhou <[email protected]>NAK, that will allocate an array for the fence again, which we wanted to avoid.
I don't got your means, the **array just to store fence temporary, freed at the end.
Quoted 2 lines
We should just drop the fence reference directly after waiting for it.
How to handle err case in the middle.
Regards,
David Zhou
Quoted 52 lines
Regards,
Christian.Quoted 48 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +12
-5@@ -1216,22 +1216,28 @@ static int amdgpu_cs_wait_all_fences(structamdgpu_device *adev, struct drm_amdgpu_fence *fences) { uint32_t fence_count = wait->in.fence_count; +struct fence **array;unsigned int i;long r =1 ; + array =kcalloc (fence_count,sizeof (struct fence *),GFP_KERNEL ); + +if (array ==NULL ) +return -ENOMEM ;for (i =0 ; i < fence_count; i++) {struct fence *fence;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout_ns); fence =amdgpu_cs_get_fence (adev, filp, &fences[i]); -if (IS_ERR (fence)) -return PTR_ERR (fence); -else if (!fence) +if (IS_ERR (fence)) { + r =PTR_ERR (fence); + goto err; + }else if (!fence)continue ; - + array[i] = fence; r =kcl_fence_wait_timeout (fence, true, timeout);if (r <0 ) -return r; + goto err;if (r ==0 )break ;@@ -1240,7 +1246,14 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,memset (wait,0 ,sizeof (*wait)); wait->out.status = (r >0 ); - return 0; + r =0 ; +
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev, · line 1259
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6
-0+err: +for (i =0 ; i < fence_count; i++) +fence_put (array[i]); +kfree (array); + +return r; }/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Am 07.04.2017 um 10:46 schrieb zhoucm1:
Quoted 9 lines · Christian König
Quoted 5 lines
Am 07.04.2017 um 05:36 schrieb Chunming Zhou:
Quoted 2 lines
Change-Id Ib3e271e00e49f10152c1b3eace981a6bf78820deSigned-off-by Chunming Zhou <[email protected]>NAK, that will allocate an array for the fence again, which we wanted to avoid.
I don't got your means, the **array just to store fence temporary, freed at the end.
Yeah, but that is unnecessary. We created this function to just avoid that.
Quoted 4 lines
Quoted 3 lines
We should just drop the fence reference directly after waiting for it.
How to handle err case in the middle.
just put a fence_put() directly after fence_wait_timeout(). We don't need to keep a reference to the fence till the end.
Regards,
Christian.
Quoted 67 lines
Regards,
David ZhouQuoted 53 lines
Regards,
Christian.Quoted 49 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +12
-5@@ -1216,22 +1216,28 @@ static int amdgpu_cs_wait_all_fences(structamdgpu_device *adev, struct drm_amdgpu_fence *fences) { uint32_t fence_count = wait->in.fence_count; +struct fence **array;unsigned int i;long r =1 ; + array =kcalloc (fence_count,sizeof (struct fence *),GFP_KERNEL ); + +if (array ==NULL ) +return -ENOMEM ;for (i =0 ; i < fence_count; i++) {struct fence *fence;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout_ns); fence =amdgpu_cs_get_fence (adev, filp, &fences[i]); -if (IS_ERR (fence)) -return PTR_ERR (fence); -else if (!fence) +if (IS_ERR (fence)) { + r =PTR_ERR (fence); + goto err; + }else if (!fence)continue ; - + array[i] = fence; r =kcl_fence_wait_timeout (fence, true, timeout);if (r <0 ) -return r; + goto err;if (r ==0 )break ;@@ -1240,7 +1246,14 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,memset (wait,0 ,sizeof (*wait)); wait->out.status = (r >0 ); - return 0; + r =0 ; +Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev, · line 1259
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6
-0+err: +for (i =0 ; i < fence_count; i++) +fence_put (array[i]); +kfree (array); + +return r; }/**
Quoted 4 lines
_______________________________________________
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
A message that is not in the archive (sent off-list or not yet received): 6aa1afcf-b2d3-ea84-b08c-3520fffb0b7c-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 11 lines · Christian König
Am 07.04.2017 um 10:46 schrieb zhoucm1:
Quoted 9 lines · Christian König
Quoted 5 lines
Am 07.04.2017 um 05:36 schrieb Chunming Zhou:
Quoted 2 lines
Change-Id Ib3e271e00e49f10152c1b3eace981a6bf78820deSigned-off-by Chunming Zhou <[email protected]>NAK, that will allocate an array for the fence again, which we wanted to avoid.
I don't got your means, the **array just to store fence temporary, freed at the end.
Quoted 8 lines
Yeah, but that is unnecessary. We created this function to just avoid that.
Quoted 4 lines
Quoted 3 lines
We should just drop the fence reference directly after waiting for it.
How to handle err case in the middle.
just put a
fence_put()directly afterfence_wait_timeout(). We don't need to keep a reference to the fence till the end.
I see your mean, will send V2 soon.
Regards,
David Zhou
Quoted 78 lines
Regards,
Christian.Quoted 72 lines
Regards,
David ZhouQuoted 54 lines
Regards,
Christian.Quoted 50 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +12
-5@@ -1216,22 +1216,28 @@ static int amdgpu_cs_wait_all_fences(structamdgpu_device *adev, struct drm_amdgpu_fence *fences) { uint32_t fence_count = wait->in.fence_count; +struct fence **array;unsigned int i;long r =1 ; + array =kcalloc (fence_count,sizeof (struct fence *),GFP_KERNEL ); + +if (array ==NULL ) +return -ENOMEM ;for (i =0 ; i < fence_count; i++) {struct fence *fence;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout_ns); fence =amdgpu_cs_get_fence (adev, filp, &fences[i]); -if (IS_ERR (fence)) -return PTR_ERR (fence); -else if (!fence) +if (IS_ERR (fence)) { + r =PTR_ERR (fence); + goto err; + }else if (!fence)continue ; - + array[i] = fence; r =kcl_fence_wait_timeout (fence, true, timeout);if (r <0 ) -return r; + goto err;if (r ==0 )break ;@@ -1240,7 +1246,14 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,memset (wait,0 ,sizeof (*wait)); wait->out.status = (r >0 ); - return 0; + r =0 ; +Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_wait_all_fences(struct · line 1259
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6
-0+err: +for (i =0 ; i < fence_count; i++) +fence_put (array[i]); +kfree (array); + +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