Skip to contentSkip to conversation

drm/amdgpu: Initialize value of r in amdgpu_fill_buffer()

PATCH In review Souptick Joarder 2 participants 2 messages Feb 18, 2022 – Feb 21, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Initialize value of r in amdgpu_fill_buffer()

From: "Souptick Joarder (HPE)" <[email protected]>

Kernel test robot reported warning -> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:2129:2: warning: Undefined or garbage value returned to caller [clang-analyzer-core. uninitialized.UndefReturn]

Initialize r inside amdgpu_fill_buffer().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 414a22dddc78..5fafb223177f 100644
@@ -2089,7 +2089,7 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
 	struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
 	struct dma_fence *fence = NULL;
 	struct amdgpu_res_cursor dst;
-	int r;
+	int r = 0;
 
 	if (!adev->mman.buffer_funcs_enabled) {
 		DRM_ERROR("Trying to clear memory with ring turned off.\n");
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Am 18.02.22 um 19:53 schrieb Souptick Joarder:

Quoted 6 lines

From: "Souptick Joarder (HPE)" <[email protected]>

Kernel test robot reported warning -> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:2129:2: warning: Undefined or garbage value returned to caller [clang-analyzer-core. uninitialized.UndefReturn]

Good catch, but that fix is usually seen as bad practice.

The warning is a false positive because the code path which would lead to returning an undefined value can never happen. There is just no way the compiler could know that.

I suggest to better initialize the return value directly before the error handling to indicate that when we have reached this point we can return success safely.

Regards,
Christian.

Quoted 22 lines

Initialize r inside amdgpu_fill_buffer().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 414a22dddc78..5fafb223177f 100644
@@ -2089,7 +2089,7 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
  	struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
  	struct dma_fence *fence = NULL;
  	struct amdgpu_res_cursor dst;
-	int r;
+	int r = 0;
 
  	if (!adev->mman.buffer_funcs_enabled) {
  		DRM_ERROR("Trying to clear memory with ring turned off.\n");