drm/amdgpu: Fixes to amdgpu_userq_fence_driver_alloc()
Subsystems (2)
v2 cover drm/amdgpu: Fixes to amdgpu_userq_fence_driver_alloc()
This fixes a double free on one error path in amdgpu_userq_fence_driver_alloc() and cleans up another error path.
v2:
Did some additional cleanup
Dan Carpenter (2):
drm/amdgpu: Fix double free in amdgpu_userq_fence_driver_alloc() drm/amdgpu: Clean up error handling in
amdgpu_userq_fence_driver_alloc()
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
Signature · 1 line
2.47.2
PATCH v2 1/2 drm/amdgpu: Fix double free in amdgpu_userq_fence_driver_alloc()
The goto frees "fence_drv" so this is a double free bug. There is no need to call amdgpu_seq64_free(adev, fence_drv->va) since the seq64 allocation failed so change the goto to goto free_fence_drv. Also propagate the error code from amdgpu_seq64_alloc() instead of hard coding it to -ENOMEM.
---
v2: No change.
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2 -5
@@ -84,11 +84,8 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,/* Acquire seq64 memory */ r =amdgpu_seq64_alloc (adev, &fence_drv->va, &fence_drv->gpu_addr, &fence_drv->cpu_addr); -if (r) { -kfree (fence_drv); - r = -ENOMEM ; - goto free_seq64; - } +if (r) + goto free_fence_drv;memset (fence_drv->cpu_addr,0 ,sizeof (u64));
Signature · 1 line
2.47.2
PATCH v2 2/2 drm/amdgpu: Clean up error handling in amdgpu_userq_fence_driver_alloc()
In reply to Dan Carpenter1) Checkpatch complains if we print an error message for kzalloc() failure. The kzalloc() failure already has it's own error messages built in. Also this allocation is small enough that it is guaranteed to succeed.
2) Return directly instead of doing a goto free_fence_drv. The "fence_drv" is already NULL so no cleanup is necessary.
---
v2: New patch
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2 -5
@@ -75,11 +75,8 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,int r; fence_drv =kzalloc (sizeof (*fence_drv),GFP_KERNEL ); -if (!fence_drv) { -DRM_ERROR ("Failed to allocate memory for fence driver\n" ); - r = -ENOMEM ; - goto free_fence_drv; - } +if (!fence_drv) +return -ENOMEM ;/* Acquire seq64 memory */ r = amdgpu_seq64_alloc(adev, &fence_drv->va, &fence_drv->gpu_addr,
Signature · 1 line
2.47.2
Re: [PATCH v2 1/2] drm/amdgpu: Fix double free in amdgpu_userq_fence_driver_alloc()
In reply to Dan CarpenterQuoted 32 lines · Dan Carpenter
The goto frees "
fence_drv" so this is a double free bug. There is no need to callamdgpu_seq64_free(adev, fence_drv->va)since the seq64 allocation failed so change the goto to gotofree_fence_drv. Also propagate the error code fromamdgpu_seq64_alloc()instead of hard coding it to-ENOMEM.Fixes e7cf21fbb277 ("drm/amdgpu: Few optimization and fixes for userq fence driver")Signed-off-by Dan Carpenter <[email protected]>---
v2: No change.drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-5@@ -84,11 +84,8 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,/* Acquire seq64 memory */ r =amdgpu_seq64_alloc (adev, &fence_drv->va, &fence_drv->gpu_addr, &fence_drv->cpu_addr); -if (r) { -kfree (fence_drv); - r = -ENOMEM ; - goto free_seq64; - } +if (r) + goto free_fence_drv;memset (fence_drv->cpu_addr,0 ,sizeof (u64));
Re: [PATCH v2 2/2] drm/amdgpu: Clean up error handling in amdgpu_userq_fence_driver_alloc()
In reply to Dan CarpenterQuoted 32 lines · Dan Carpenter
1) Checkpatch complains if we print an error message for
kzalloc()failure. Thekzalloc()failure already has it's own error messages built in. Also this allocation is small enough that it is guaranteed to succeed.
2) Return directly instead of doing a gotofree_fence_drv. The "fence_drv" is already NULL so no cleanup is necessary.Signed-off-by Dan Carpenter <[email protected]>---
v2: New patchdrivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-5@@ -75,11 +75,8 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,int r; fence_drv =kzalloc (sizeof (*fence_drv),GFP_KERNEL ); -if (!fence_drv) { -DRM_ERROR ("Failed to allocate memory for fence driver\n" ); - r = -ENOMEM ; - goto free_fence_drv; - } +if (!fence_drv) +return -ENOMEM ;/* Acquire seq64 memory */ r = amdgpu_seq64_alloc(adev, &fence_drv->va, &fence_drv->gpu_addr,
Alex Deucher
AppliedRe: [PATCH v2 2/2] drm/amdgpu: Clean up error handling in amdgpu_userq_fence_driver_alloc()
Applied the series. Thanks!
Quoted 36 lines · Arvind
Reviewed-by Arvind Yadav <[email protected]>Quoted 32 lines · Dan Carpenter
1) Checkpatch complains if we print an error message for
kzalloc()failure. Thekzalloc()failure already has it's own error messages built in. Also this allocation is small enough that it is guaranteed to succeed.
2) Return directly instead of doing a gotofree_fence_drv. The "fence_drv" is already NULL so no cleanup is necessary.Signed-off-by Dan Carpenter <[email protected]>---
v2: New patchdrivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-5@@ -75,11 +75,8 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,int r; fence_drv =kzalloc (sizeof (*fence_drv),GFP_KERNEL ); -if (!fence_drv) { -DRM_ERROR ("Failed to allocate memory for fence driver\n" ); - r = -ENOMEM ; - goto free_fence_drv; - } +if (!fence_drv) +return -ENOMEM ;/* Acquire seq64 memory */ r = amdgpu_seq64_alloc(adev, &fence_drv->va, &fence_drv->gpu_addr,