drm/amdgpu: Initialize r in VM and TTM buffer helpers
Subsystems (2)
v2 cover drm/amdgpu: Initialize r in VM and TTM buffer helpers
Two fixes in drm/amdgpu for uninitialized return-value regressions found via Clang -Wconditional-uninitialized on an x86_64 allyesconfig build:
1. Set r = 0 in the 'else if (!bo)' branch of amdgpu_vm_bo_update().
2. Set r = 0 right after the while loop before 'error:' in amdgpu_ttm_clear_buffer().
Build-tested with LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not runtime-tested on AMDGPU hardware.
v2:
- Keep 'int r;' uninitialized at declaration in both functions so future missing-assignment paths are not masked; instead set 'r = 0;' inside 'else if (!bo)' in patch 1/2 and directly before 'error:' in patch 2/2 (Christian König).
v1: https://lore.kernel.org/r/[email protected]
Ian Rogers (2):
drm/amdgpu: initialize r in amdgpu_vm_bo_update() drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer()
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 1 + 2 files changed, 3 insertions(+)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v2 1/2 drm/amdgpu: initialize r in amdgpu_vm_bo_update()
Commit bc566781845b ("drm/amdgpu: stop syncing PRT map operations") added an 'else if (!bo)' branch in amdgpu_vm_bo_update() that does not assign 'r'. Because fpriv->prt_va has bo == NULL and is updated on every command submission, userqueue validation, and KFD VM restore, calling amdgpu_vm_bo_update(adev, fpriv->prt_va, false) when bo_va->invalids is empty skips the mapping loop and returns uninitialized stack variable 'r'.
Set 'r = 0' in the 'else if (!bo)' branch.
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wconditional-uninitialized enabled; fix and changelog drafted with an AI coding assistant. Build-tested under LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not runtime-tested on AMD GPU hardware.
---
Notes:
v2:
- Set 'r = 0;' in the 'else if (!bo)' branch instead of initializing 'r' at declaration (Christian König).
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
@@ -1323,6 +1323,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va, } }else if (!bo) { mem =NULL ; + r =0 ;/* PRT map operations don't need to sync to anything. */
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH v2 2/2 drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer()
In reply to Ian RogersIn amdgpu_ttm_clear_buffer(), 'r' is declared uninitialized. When consider_clear_status is true (such as AMDGPU_GEM_CREATE_VRAM_CLEARED allocations) and all backing buddy blocks already have DRM_BUDDY_CLEARED set, every iteration of the cursor loop hits 'continue' without assigning 'r', returning uninitialized stack memory to amdgpu_bo_create().
Set 'r = 0' after the cursor loop directly before the 'error:' label.
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wconditional-uninitialized enabled; fix and changelog drafted with an AI coding assistant. Build-tested under LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not runtime-tested on AMD GPU hardware.
---
Notes:
v2:
- Set 'r = 0;' directly before the 'error:' label instead of initializing 'r' at declaration (Christian König).
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
@@ -2711,6 +2711,8 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_ttm_buffer_entity *entity,amdgpu_res_next (&dst, cur_size); } + r =0 ; + error:mutex_unlock (&entity->lock); *out_fence = fence;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
Alex will probably pick the patches up, if not please ping me again.
Regards,
Christian.
Quoted 27 lines · Ian Rogers
Two fixes in drm/amdgpu for uninitialized return-value regressions found via Clang -Wconditional-uninitialized on an
x86_64allyesconfig build:1. Set r = 0 in the 'else if (!bo)' branch of
amdgpu_vm_bo_update().
2. Set r = 0 right after the while loop before 'error:' inamdgpu_ttm_clear_buffer().Build-tested with LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not runtime-tested on AMDGPU hardware.
v2:
- Keep 'int r;' uninitialized at declaration in both functions so future missing-assignment paths are not masked; instead set 'r = 0;' inside 'else if (!bo)' in patch 1/2 and directly before 'error:' in patch 2/2 (Christian König).v1: https://lore.kernel.org/r/[email protected]
Ian Rogers (2):
drm/amdgpu: initialize r inamdgpu_vm_bo_update()drm/amdgpu: initialize r inamdgpu_ttm_clear_buffer()drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 1 + 2 files changed, 3 insertions(+)
Alex Deucher
AppliedApplied. Thanks!
Quoted 37 lines · Christian König
Alex will probably pick the patches up, if not please ping me again.
Regards,
Christian.Quoted 27 lines · Ian Rogers
Two fixes in drm/amdgpu for uninitialized return-value regressions found via Clang -Wconditional-uninitialized on an
x86_64allyesconfig build:1. Set r = 0 in the 'else if (!bo)' branch of
amdgpu_vm_bo_update().
2. Set r = 0 right after the while loop before 'error:' inamdgpu_ttm_clear_buffer().Build-tested with LLVM=1 W=1 (-Werror) and -Wconditional-uninitialized; not runtime-tested on AMDGPU hardware.
v2:
- Keep 'int r;' uninitialized at declaration in both functions so future missing-assignment paths are not masked; instead set 'r = 0;' inside 'else if (!bo)' in patch 1/2 and directly before 'error:' in patch 2/2 (Christian König).v1: https://lore.kernel.org/r/[email protected]
Ian Rogers (2):
drm/amdgpu: initialize r inamdgpu_vm_bo_update()drm/amdgpu: initialize r inamdgpu_ttm_clear_buffer()drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 1 + 2 files changed, 3 insertions(+)