Skip to contentSkip to conversation

drm/amdgpu: fix return of an uninitialized value in variable ret

PATCH In review Colin King 3 participants 3 messages May 10, 2019 – May 11, 2019

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 drm/amdgpu: fix return of an uninitialized value in variable ret

From: Colin Ian King <[email protected]>

In the case where is_enable is false and lo_base_addr is non-zero the variable ret has not been initialized and is being checked for non-zero and potentially garbage is being returned. Fix this by not returning ret but instead returning -EINVAL on the zero lo_base_addr case.

Addresses-Coverity: ("Uninitialized scalar variable")

Fixes a6ac0b44bab9 ("drm/amdgpu: add df perfmon regs and funcs for xgmi")
---
 drivers/gpu/drm/amd/amdgpu/df_v3_6.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/df_v3_6.c +1 -4
index a5c3558869fb..8c09bf994acd 100644
@@ -398,10 +398,7 @@ static int df_v3_6_start_xgmi_link_cntr(struct amdgpu_device *adev,
 				NULL);
 
 		if (lo_base_addr == 0)
-			ret = -EINVAL;
-
-		if (ret)
-			return ret;
+			return -EINVAL;
 
 		lo_val = RREG32_PCIE(lo_base_addr);
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

In the case where is_enable is false and lo_base_addr is non-zero the variable ret has not been initialized and is being checked for non-zero and potentially garbage is being returned. Fix this by not returning ret but instead returning -EINVAL on the zero lo_base_addr case.

Addresses-Coverity: ("Uninitialized scalar variable")

Fixes a6ac0b44bab9 ("drm/amdgpu: add df perfmon regs and funcs for xgmi")
---
 drivers/gpu/drm/amd/amdgpu/df_v3_6.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/df_v3_6.c +0 -0
index a5c3558869fb..8c09bf994acd 100644

drivers/gpu/drm/amd/amdgpu/df_v3_6.c static int df_v3_6_start_xgmi_link_cntr(struct amdgpu_device *adev, · line 401

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/df_v3_6.c +1 -4
@@ -398,10 +398,7 @@ static int df_v3_6_start_xgmi_link_cntr(struct amdgpu_device *adev,
 				NULL);
 
 		if (lo_base_addr == 0)
-			ret = -EINVAL;
-
-		if (ret)
-			return ret;
+			return -EINVAL;

From a naive reading of the code without knowing the hardware spec then you would probably think that lo_base_addr can also be uninitialized.

<sad face emoji>

regards,
dan carpenter

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by on v1 1/1
#2 lore raw
In reply to Colin King
Quoted 10 lines · Colin King

From: Colin Ian King <[email protected]>

In the case where is_enable is false and lo_base_addr is non-zero the variable ret has not been initialized and is being checked for non-zero and potentially garbage is being returned. Fix this by not returning ret but instead returning -EINVAL on the zero lo_base_addr case.

Addresses-Coverity: ("Uninitialized scalar variable")

Fixes a6ac0b44bab9 ("drm/amdgpu: add df perfmon regs and funcs for xgmi")

This fixes a clang warning complaining about the same thing.

Quoted 23 lines
---
 drivers/gpu/drm/amd/amdgpu/df_v3_6.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/df_v3_6.c +1 -4
index a5c3558869fb..8c09bf994acd 100644
@@ -398,10 +398,7 @@ static int df_v3_6_start_xgmi_link_cntr(struct amdgpu_device *adev,
 				NULL);
 
 		if (lo_base_addr == 0)
-			ret = -EINVAL;
-
-		if (ret)
-			return ret;
+			return -EINVAL;
 
 		lo_val = RREG32_PCIE(lo_base_addr);
 
Signature · 1 line
2.20.1