Skip to contentSkip to conversation

drm/amdgpu: fix uninitialized scalar variable warning

PATCH Superseded Tim Huang 2 participants 6 messages Apr 23, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Tim Huang

author
#0 lore raw

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
index d95555dc5485..6b8a58f501d3 100644
@@ -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
maintainer
#1 lore raw

Am 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
---
  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
index d95555dc5485..6b8a58f501d3 100644
@@ -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:
author
#2 lore raw

[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_size uninitialized 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
---
  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
index d95555dc5485..6b8a58f501d3 100644
@@ -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:
author
#3 lore raw

[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_size uninitialized 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.

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.

---
  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
index d95555dc5485..6b8a58f501d3 100644
@@ -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:
maintainer
#5 lore raw
In reply to Huang, Tim

The 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 warning

Am 23.04.24 um 08:28 schrieb Tim Huang:

Quoted 2 lines

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?

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 19 lines
---
   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
index d95555dc5485..6b8a58f501d3 100644
@@ -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:
maintainer
#4 lore raw
In reply to Huang, Tim

Am 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 warning

Am 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 the fw_size uninitialized 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.

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.

---
   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
index d95555dc5485..6b8a58f501d3 100644
@@ -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: