drm/amdgpu: Remove hidden double memset from amdgpu_vm_pt_clear()
Subsystems (2)
PATCH 1/1 drm/amdgpu: Remove hidden double memset from amdgpu_vm_pt_clear()
From: Tvrtko Ursulin <[email protected]>
When CONFIG_INIT_STACK_ALL_ZERO is set and so -ftrivial-auto-var-init=zero compiler option active, compiler fails to notice that later in amdgpu_vm_pt_clear() there is a second memset to clear the same on stack struct amdgpu_vm_update_params.
If we replace this memset with an explicit automatic variable initializer, compiler can then see it and avoid clearing this struct twice.
---
This is perhaps a bit questionable, regardless of how annoying it is to know there is this double memset.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +1 -2
@@ -361,7 +361,7 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm, {unsigned int level = adev->vm_manager.root_level;struct ttm_operation_ctx ctx = { true, false }; -struct amdgpu_vm_update_params params; +struct amdgpu_vm_update_params params = { };struct amdgpu_bo *ancestor = &vmbo->bo;unsigned int entries;struct amdgpu_bo *bo = &vmbo->bo;
@@ -398,7 +398,6 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (r) goto exit; -memset (¶ms,0 ,sizeof (params)); params.adev = adev; params.vm = vm; params.immediate = immediate;
Signature · 1 line
2.44.0
Quoted 32 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
When
CONFIG_INIT_STACK_ALL_ZEROis set and so -ftrivial-auto-var-init=zero compiler option active, compiler fails to notice that later inamdgpu_vm_pt_clear()there is a second memset to clear the same on stack structamdgpu_vm_update_params.If we replace this memset with an explicit automatic variable initializer, compiler can then see it and avoid clearing this struct twice.
Signed-off-by Tvrtko Ursulin <[email protected]>---
This is perhaps a bit questionable, regardless of how annoying it is to know there is this double memset.--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +1
-1@@ -361,7 +361,7 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm, {unsigned int level = adev->vm_manager.root_level;struct ttm_operation_ctx ctx = { true, false }; -struct amdgpu_vm_update_params params; +struct amdgpu_vm_update_params params = { };struct amdgpu_bo *ancestor = &vmbo->bo;unsigned int entries;struct amdgpu_bo *bo = &vmbo->bo;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 403
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +0
-1@@ -398,7 +398,6 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (r) goto exit; -memset (¶ms,0 ,sizeof (params)); params.adev = adev; params.vm = vm; params.immediate = immediate;
Or even move all above three into the automatic initializer since all are the function input arguments.
Regards,
Tvrtko