All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] drm/amdgpu: Initialize r in VM and TTM buffer helpers
@ 2026-11-19 17:07 Ian Rogers
  2026-11-19 17:07 ` [PATCH 1/2] drm/amdgpu: initialize r in amdgpu_vm_bo_update() Ian Rogers
  2026-11-19 17:07 ` [PATCH 2/2] drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer() Ian Rogers
  0 siblings, 2 replies; 7+ messages in thread
From: Ian Rogers @ 2026-11-19 17:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, llvm, Elkin Cruz, Ian Rogers

Two fixes in drm/amdgpu for uninitialized return-value regressions
found via Clang -Wconditional-uninitialized on an x86_64
allyesconfig build:

1. Initialize r = 0 in amdgpu_vm_bo_update().
2. Initialize r = 0 in amdgpu_ttm_clear_buffer().

Build-tested with LLVM=1 W=1 (-Werror); not runtime-tested on
AMDGPU hardware.

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  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.56.1.708.g77570a6a1d-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] drm/amdgpu: initialize r in amdgpu_vm_bo_update()
  2026-11-19 17:07 [PATCH 0/2] drm/amdgpu: Initialize r in VM and TTM buffer helpers Ian Rogers
@ 2026-11-19 17:07 ` Ian Rogers
  2026-11-20 12:07   ` Christian König
  2026-11-19 17:07 ` [PATCH 2/2] drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer() Ian Rogers
  1 sibling, 1 reply; 7+ messages in thread
From: Ian Rogers @ 2026-11-19 17:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, llvm, Elkin Cruz, Ian Rogers

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'.

Initialize 'r' to 0.

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.

Fixes: bc566781845b ("drm/amdgpu: stop syncing PRT map operations")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 82b9b2d5d0cf..091589b2c524 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1303,7 +1303,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
 	uint64_t vram_base;
 	uint64_t flags;
 	bool uncached;
-	int r;
+	int r = 0;
 
 	amdgpu_sync_create(&sync);
 	if (clear) {
-- 
2.56.1.708.g77570a6a1d-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer()
  2026-11-19 17:07 [PATCH 0/2] drm/amdgpu: Initialize r in VM and TTM buffer helpers Ian Rogers
  2026-11-19 17:07 ` [PATCH 1/2] drm/amdgpu: initialize r in amdgpu_vm_bo_update() Ian Rogers
@ 2026-11-19 17:07 ` Ian Rogers
  2026-11-20 12:11   ` Christian König
  1 sibling, 1 reply; 7+ messages in thread
From: Ian Rogers @ 2026-11-19 17:07 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, llvm, Elkin Cruz, Ian Rogers

In 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().

Initialize 'r' to 0.

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.

Fixes: 23bd7e67961e ("drm/amdgpu: get rid of amdgpu_ttm_clear_buffer")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 0f86777250fc..280fcdfb9cca 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2675,7 +2675,7 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_ttm_buffer_entity *entity,
 	struct dma_fence *fence = NULL;
 	struct amdgpu_res_cursor dst;
 	bool vm_needs_flush = false;
-	int r;
+	int r = 0;
 
 	if (!entity)
 		return -EINVAL;
-- 
2.56.1.708.g77570a6a1d-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] drm/amdgpu: initialize r in amdgpu_vm_bo_update()
  2026-11-19 17:07 ` [PATCH 1/2] drm/amdgpu: initialize r in amdgpu_vm_bo_update() Ian Rogers
@ 2026-11-20 12:07   ` Christian König
  2026-11-20 17:30     ` Ian Rogers
  0 siblings, 1 reply; 7+ messages in thread
From: Christian König @ 2026-11-20 12:07 UTC (permalink / raw)
  To: Ian Rogers, Alex Deucher, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, llvm, Elkin Cruz



On 11/19/26 18:07, Ian Rogers wrote:
> 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'.
> 
> Initialize 'r' to 0.
> 
> 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.
> 
> Fixes: bc566781845b ("drm/amdgpu: stop syncing PRT map operations")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 82b9b2d5d0cf..091589b2c524 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1303,7 +1303,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
>  	uint64_t vram_base;
>  	uint64_t flags;
>  	bool uncached;
> -	int r;
> +	int r = 0;

Good catch, but please don't initialize return variables a default value.

That is often seen as bad coding style and often hides problems instead of fixing them.

Instead just initialize r in the if branch where it is missing.

Thanks,
Christian.

>  
>  	amdgpu_sync_create(&sync);
>  	if (clear) {


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer()
  2026-11-19 17:07 ` [PATCH 2/2] drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer() Ian Rogers
@ 2026-11-20 12:11   ` Christian König
  2026-11-20 17:31     ` Ian Rogers
  0 siblings, 1 reply; 7+ messages in thread
From: Christian König @ 2026-11-20 12:11 UTC (permalink / raw)
  To: Ian Rogers, Alex Deucher, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, llvm, Elkin Cruz



On 11/19/26 18:07, Ian Rogers wrote:
> In 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().
> 
> Initialize 'r' to 0.
> 
> 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.
> 
> Fixes: 23bd7e67961e ("drm/amdgpu: get rid of amdgpu_ttm_clear_buffer")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 0f86777250fc..280fcdfb9cca 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -2675,7 +2675,7 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_ttm_buffer_entity *entity,
>  	struct dma_fence *fence = NULL;
>  	struct amdgpu_res_cursor dst;
>  	bool vm_needs_flush = false;
> -	int r;
> +	int r = 0;

Please initialize r directly before the error label, apart from that looks good to me.

Regards,
Christian.

>  
>  	if (!entity)
>  		return -EINVAL;


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] drm/amdgpu: initialize r in amdgpu_vm_bo_update()
  2026-11-20 12:07   ` Christian König
@ 2026-11-20 17:30     ` Ian Rogers
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2026-11-20 17:30 UTC (permalink / raw)
  To: Christian König
  Cc: Alex Deucher, David Airlie, Simona Vetter, amd-gfx, dri-devel,
	linux-kernel, llvm, Elkin Cruz

On Fri, Nov 20, 2026 at 4:08 AM Christian König
<christian.koenig@amd.com> wrote:
>
>
>
> On 11/19/26 18:07, Ian Rogers wrote:
> > 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'.
> >
> > Initialize 'r' to 0.
> >
> > 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.
> >
> > Fixes: bc566781845b ("drm/amdgpu: stop syncing PRT map operations")
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > index 82b9b2d5d0cf..091589b2c524 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> > @@ -1303,7 +1303,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
> >       uint64_t vram_base;
> >       uint64_t flags;
> >       bool uncached;
> > -     int r;
> > +     int r = 0;
>
> Good catch, but please don't initialize return variables a default value.
>
> That is often seen as bad coding style and often hides problems instead of fixing them.
>
> Instead just initialize r in the if branch where it is missing.

Makes sense - keeping 'int r;' uninitialized at declaration avoids
masking future missing-assignment paths. I'll set 'r = 0;' inside the
'else if (!bo)' branch in v2.

Thanks,
Ian

> Thanks,
> Christian.
>
> >
> >       amdgpu_sync_create(&sync);
> >       if (clear) {
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer()
  2026-11-20 12:11   ` Christian König
@ 2026-11-20 17:31     ` Ian Rogers
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2026-11-20 17:31 UTC (permalink / raw)
  To: Christian König
  Cc: Alex Deucher, David Airlie, Simona Vetter, amd-gfx, dri-devel,
	linux-kernel, llvm, Elkin Cruz

On Fri, Nov 20, 2026 at 4:12 AM Christian König
<christian.koenig@amd.com> wrote:
>
>
>
> On 11/19/26 18:07, Ian Rogers wrote:
> > In 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().
> >
> > Initialize 'r' to 0.
> >
> > 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.
> >
> > Fixes: 23bd7e67961e ("drm/amdgpu: get rid of amdgpu_ttm_clear_buffer")
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> > index 0f86777250fc..280fcdfb9cca 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> > @@ -2675,7 +2675,7 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_ttm_buffer_entity *entity,
> >       struct dma_fence *fence = NULL;
> >       struct amdgpu_res_cursor dst;
> >       bool vm_needs_flush = false;
> > -     int r;
> > +     int r = 0;
>
> Please initialize r directly before the error label, apart from that looks good to me.

Will do - I'll move 'r = 0;' to right after the while loop directly
before the 'error:' label in v2.

Thanks,
Ian

> Regards,
> Christian.
>
> >
> >       if (!entity)
> >               return -EINVAL;
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-20 17:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 17:07 [PATCH 0/2] drm/amdgpu: Initialize r in VM and TTM buffer helpers Ian Rogers
2026-11-19 17:07 ` [PATCH 1/2] drm/amdgpu: initialize r in amdgpu_vm_bo_update() Ian Rogers
2026-11-20 12:07   ` Christian König
2026-11-20 17:30     ` Ian Rogers
2026-11-19 17:07 ` [PATCH 2/2] drm/amdgpu: initialize r in amdgpu_ttm_clear_buffer() Ian Rogers
2026-11-20 12:11   ` Christian König
2026-11-20 17:31     ` Ian Rogers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.