drm/amdgpu: fix uninitialized scalar variable warning
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix uninitialized scalar variable warning
Clear warning that uses uninitialized value fw_size.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -1
@@ -1084,7 +1084,7 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device *adev,const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0;struct amdgpu_firmware_info *info =NULL ;const struct firmware *ucode_fw; -unsigned int fw_size; +unsigned int fw_size =0 ;switch (ucode_id) {case AMDGPU_UCODE_ID_CP_PFP :
Signature · 1 line
2.39.2
Christian König
maintainerAm 23.04.24 um 08:28 schrieb Tim Huang:
Quoted 1 line
Clear warning that uses uninitialized value
fw_size.
In which case is the fw_size uninitialized and why setting it to zero helps in that case?
Regards,
Christian.
Quoted 19 lines
Signed-off-by Tim Huang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-1@@ -1084,7 +1084,7 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device *adev,const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0;struct amdgpu_firmware_info *info =NULL ;const struct firmware *ucode_fw; -unsigned int fw_size; +unsigned int fw_size =0 ;switch (ucode_id) {case AMDGPU_UCODE_ID_CP_PFP :
[AMD Official Use Only - General]
Hi Christian,
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 23, 2024 3:43 PM
To: Huang, Tim <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix uninitialized scalar variable warning
Am 23.04.24 um 08:28 schrieb Tim Huang:
Quoted 3 lines
Clear warning that uses uninitialized value
fw_size.In which case is the
fw_sizeuninitialized and why setting it to zero helps in that case?
It's a warning that reported by the Coverity scan. When the switch case " switch (ucode_id) " got to default and Condition "adev->firmware.load_type == AMDGPU_FW_LOAD_PSP", taking true branch,
it reports " uses uninitialized value fw_size " by this line.
"adev->firmware.fw_size += ALIGN(fw_size, PAGE_SIZE);“
It may not happen if we call this function correctly, but it just clears the warning and looks harmless.
Regards,
Christian.
Quoted 20 lines
Signed-off-by Tim Huang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-1@@ -1084,7 +1084,7 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device *adev,const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0;struct amdgpu_firmware_info *info =NULL ;const struct firmware *ucode_fw; -unsigned int fw_size; +unsigned int fw_size =0 ;switch (ucode_id) {case AMDGPU_UCODE_ID_CP_PFP :
[AMD Official Use Only - General]
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Huang, Tim
Sent: Tuesday, April 23, 2024 4:01 PM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: fix uninitialized scalar variable warning
[AMD Official Use Only - General]
[AMD Official Use Only - General]
Hi Christian,
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 23, 2024 3:43 PM
To: Huang, Tim <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix uninitialized scalar variable warning
Am 23.04.24 um 08:28 schrieb Tim Huang:
Quoted 8 lines
Clear warning that uses uninitialized value
fw_size.In which case is the
fw_sizeuninitialized and why setting it to zero helps in that case?It's a warning that reported by the Coverity scan. When the switch case " switch (
ucode_id) " got to default and Condition "adev->firmware.load_type==AMDGPU_FW_LOAD_PSP", taking true branch, it reports " uses uninitialized valuefw_size" by this line. "adev->firmware.fw_size+=ALIGN(fw_size, PAGE_SIZE);“It may not happen if we call this function correctly, but it just clears the warning and looks harmless.
Hi Christian,
I think it more to fix this warning, maybe I need to print an error and just return when go to the default case of "switch (ucode_id)" , will send out a v2 patch. Thanks.
Quoted 23 lines
Regards,
Christian.Signed-off-by Tim Huang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-1@@ -1084,7 +1084,7 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device *adev,const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0;struct amdgpu_firmware_info *info =NULL ;const struct firmware *ucode_fw; -unsigned int fw_size; +unsigned int fw_size =0 ;switch (ucode_id) {case AMDGPU_UCODE_ID_CP_PFP :
Christian König
maintainerAm 23.04.24 um 10:12 schrieb Huang, Tim:
Quoted 23 lines
[AMD Official Use Only - General]
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Huang, Tim
Sent: Tuesday, April 23, 2024 4:01 PM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: fix uninitialized scalar variable warning[AMD Official Use Only - General]
[AMD Official Use Only - General]
Hi Christian,
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 23, 2024 3:43 PM
To: Huang, Tim <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix uninitialized scalar variable warningAm 23.04.24 um 08:28 schrieb Tim Huang:
Quoted 8 lines
Quoted 5 lines
Clear warning that uses uninitialized value
fw_size.
In which case is thefw_sizeuninitialized and why setting it to zero helps in that case?
It's a warning that reported by the Coverity scan. When the switch case " switch (ucode_id) " got to default and Condition "adev->firmware.load_type==AMDGPU_FW_LOAD_PSP", taking true branch, it reports " uses uninitialized valuefw_size" by this line. "adev->firmware.fw_size+=ALIGN(fw_size, PAGE_SIZE);“
It may not happen if we call this function correctly, but it just clears the warning and looks harmless.Hi Christian,
I think it more to fix this warning, maybe I need to print an error and just return when go to the default case of "switch (
ucode_id)" , will send out a v2 patch. Thanks.
Yeah, exactly that's the right idea.
Regards,
Christian.
Quoted 22 lines
Quoted 22 lines
Regards,
Christian.Signed-off-by Tim Huang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-1@@ -1084,7 +1084,7 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device *adev,const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0;struct amdgpu_firmware_info *info =NULL ;const struct firmware *ucode_fw; -unsigned int fw_size; +unsigned int fw_size =0 ;switch (ucode_id) {case AMDGPU_UCODE_ID_CP_PFP :
Christian König
maintainerThe problem is that it's a hit all case and that's usually seen as bad coding style.
In other words when one branch by accident forgets to set the fw_size we wouldn't get a warning any more and just use zero.
Please rather add setting the fw_size to zero to the default branch and maybe even add a warning when that happens.
Regards,
Christian.
Am 23.04.24 um 10:01 schrieb Huang, Tim:
Quoted 42 lines
[AMD Official Use Only - General]
Hi Christian,
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 23, 2024 3:43 PM
To: Huang, Tim <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix uninitialized scalar variable warningAm 23.04.24 um 08:28 schrieb Tim Huang:
Quoted 2 lines
Clear warning that uses uninitialized value
fw_size.
In which case is thefw_sizeuninitialized and why setting it to zero helps in that case?It's a warning that reported by the Coverity scan. When the switch case " switch (
ucode_id) " got to default and Condition "adev->firmware.load_type==AMDGPU_FW_LOAD_PSP", taking true branch,
it reports " uses uninitialized valuefw_size" by this line.
"adev->firmware.fw_size+=ALIGN(fw_size, PAGE_SIZE);“It may not happen if we call this function correctly, but it just clears the warning and looks harmless.
Regards,
Christian.Quoted 19 lines
Signed-off-by Tim Huang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1
-1@@ -1084,7 +1084,7 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device *adev,const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0;struct amdgpu_firmware_info *info =NULL ;const struct firmware *ucode_fw; -unsigned int fw_size; +unsigned int fw_size =0 ;switch (ucode_id) {case AMDGPU_UCODE_ID_CP_PFP :