Skip to contentSkip to conversation

drm/amdgpu: replace int with unsigned int for imu_v12_0.c

PATCH In review Bob Zhou 2 participants 5 messages Jun 3, 2024 – Jun 4, 2024

Subsystems (2)
lore
Share & tools
lore

Bob Zhou

author
#0 lore raw

PATCH 1/1 drm/amdgpu: replace int with unsigned int for imu_v12_0.c

The return value of RREG32_SOC15 is unsigned int, so modify variable to unsigned.

---
 drivers/gpu/drm/amd/amdgpu/imu_v12_0.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +3 -3
index 0c8ef908d112..2d6f7549c2af 100644
@@ -119,7 +119,7 @@ static int imu_v12_0_load_microcode(struct amdgpu_device *adev)
 
 static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)
 {
-	int i, imu_reg_val = 0;
+	unsigned int i, imu_reg_val = 0;
 
 	for (i = 0; i < adev->usec_timeout; i++) {
 		imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_GFX_RESET_CTRL);
@@ -138,7 +138,7 @@ static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)
 
 static void imu_v12_0_setup(struct amdgpu_device *adev)
 {
-	int imu_reg_val;
+	unsigned int imu_reg_val;
 
 	WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL0, 0xffffff);
 	WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL1, 0xffff);
@@ -157,7 +157,7 @@ static void imu_v12_0_setup(struct amdgpu_device *adev)
 
 static int imu_v12_0_start(struct amdgpu_device *adev)
 {
-	int imu_reg_val;
+	unsigned int imu_reg_val;
 
 	imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_CORE_CTRL);
 	imu_reg_val &= 0xfffffffe;
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Am 03.06.24 um 07:59 schrieb Bob Zhou:

Quoted 1 line

The return value of RREG32_SOC15 is unsigned int, so modify variable to unsigned.

And why is that an improvement?

Regards,
Christian.

Quoted 37 lines
---
  drivers/gpu/drm/amd/amdgpu/imu_v12_0.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +3 -3
index 0c8ef908d112..2d6f7549c2af 100644
@@ -119,7 +119,7 @@ static int imu_v12_0_load_microcode(struct amdgpu_device *adev)
 
  static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)
  {
-	int i, imu_reg_val = 0;
+	unsigned int i, imu_reg_val = 0;
 
  	for (i = 0; i < adev->usec_timeout; i++) {
  		imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_GFX_RESET_CTRL);
@@ -138,7 +138,7 @@ static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)
 
  static void imu_v12_0_setup(struct amdgpu_device *adev)
  {
-	int imu_reg_val;
+	unsigned int imu_reg_val;
 
  	WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL0, 0xffffff);
  	WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL1, 0xffff);
@@ -157,7 +157,7 @@ static void imu_v12_0_setup(struct amdgpu_device *adev)
 
  static int imu_v12_0_start(struct amdgpu_device *adev)
  {
-	int imu_reg_val;
+	unsigned int imu_reg_val;
 
  	imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_CORE_CTRL);
  	imu_reg_val &= 0xfffffffe;
author
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Christian,

It fixes a potential Overflowed constant (INTEGER_OVERFLOW) warning reported by Coverity.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年6月3日 15:56
To: Zhou, Bob <[email protected]>; [email protected]; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: replace int with unsigned int for imu_v12_0.c

Am 03.06.24 um 07:59 schrieb Bob Zhou:

Quoted 1 line

The return value of RREG32_SOC15 is unsigned int, so modify variable to unsigned.

And why is that an improvement?

Regards,
Christian.

Quoted 41 lines
---
  drivers/gpu/drm/amd/amdgpu/imu_v12_0.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -1
index 0c8ef908d112..2d6f7549c2af 100644
@@ -119,7 +119,7 @@ static int imu_v12_0_load_microcode(struct
 amdgpu_device *adev)
 
  static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)
  {
-     int i, imu_reg_val = 0;
+     unsigned int i, imu_reg_val = 0;
 
      for (i = 0; i < adev->usec_timeout; i++) {
              imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_GFX_RESET_CTRL); @@

-138,7 +138,7 @@ static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)

  static void imu_v12_0_setup(struct amdgpu_device *adev)
  {
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -2
-     int imu_reg_val;
+     unsigned int imu_reg_val;
 
      WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL0, 0xffffff);
      WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL1, 0xffff); @@
-157,7 +157,7 @@ static void imu_v12_0_setup(struct amdgpu_device

*adev)

  static int imu_v12_0_start(struct amdgpu_device *adev)
  {
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -1
-     int imu_reg_val;
+     unsigned int imu_reg_val;
 
      imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_CORE_CTRL);
      imu_reg_val &= 0xfffffffe;
maintainer
#3 lore raw

Am 03.06.24 um 10:53 schrieb Zhou, Bob:

Quoted 5 lines

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Christian,

It fixes a potential Overflowed constant (INTEGER_OVERFLOW) warning reported by Coverity.

You need to mention that in the commit message.

And I haven't checked the hardware docs, but it can be that this isn't the right solution for the warning. Instead you should probably use the RREG32_SOC15() macro with a mask which only leaves the valid bits around.

Only when the register is really 32bit wide you need an unsigned datatype and if that is the case I suggest to use either uint32_t or u32 instead.

Regards,
Christian.

Quoted 58 lines

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年6月3日 15:56
To: Zhou, Bob <[email protected]>; [email protected]; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: replace int with unsigned int for imu_v12_0.c

Am 03.06.24 um 07:59 schrieb Bob Zhou:

Quoted 1 line

The return value of RREG32_SOC15 is unsigned int, so modify variable to unsigned.

And why is that an improvement?

Regards,
Christian.

Quoted 40 lines
---
   drivers/gpu/drm/amd/amdgpu/imu_v12_0.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -1
index 0c8ef908d112..2d6f7549c2af 100644
@@ -119,7 +119,7 @@ static int imu_v12_0_load_microcode(struct
 amdgpu_device *adev)
 
   static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)
   {
-     int i, imu_reg_val = 0;
+     unsigned int i, imu_reg_val = 0;
 
       for (i = 0; i < adev->usec_timeout; i++) {
               imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_GFX_RESET_CTRL); @@

-138,7 +138,7 @@ static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)

   static void imu_v12_0_setup(struct amdgpu_device *adev)
   {
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -2
-     int imu_reg_val;
+     unsigned int imu_reg_val;
 
       WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL0, 0xffffff);
       WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL1, 0xffff); @@
-157,7 +157,7 @@ static void imu_v12_0_setup(struct amdgpu_device

*adev)

   static int imu_v12_0_start(struct amdgpu_device *adev)
   {
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -1
-     int imu_reg_val;
+     unsigned int imu_reg_val;
 
       imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_CORE_CTRL);
       imu_reg_val &= 0xfffffffe;
author
#4 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Christian,

Thanks for your comments, the RREG32_SOC15() macro should return the 32bit wide value so it couldn't need the mask. And I will send out v2 patch to modify the commit message and use uint32_t or u32 instead .

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年6月3日 19:11
To: Zhou, Bob <[email protected]>; [email protected]; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: replace int with unsigned int for imu_v12_0.c

Am 03.06.24 um 10:53 schrieb Zhou, Bob:

Quoted 5 lines

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Christian,

It fixes a potential Overflowed constant (INTEGER_OVERFLOW) warning reported by Coverity.

You need to mention that in the commit message.

And I haven't checked the hardware docs, but it can be that this isn't the right solution for the warning. Instead you should probably use the RREG32_SOC15() macro with a mask which only leaves the valid bits around.

Only when the register is really 32bit wide you need an unsigned datatype and if that is the case I suggest to use either uint32_t or u32 instead.

Regards,
Christian.

Quoted 63 lines

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年6月3日 15:56
To: Zhou, Bob <[email protected]>; [email protected]; Huang, Tim <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: replace int with unsigned int for imu_v12_0.c

Am 03.06.24 um 07:59 schrieb Bob Zhou:

Quoted 1 line

The return value of RREG32_SOC15 is unsigned int, so modify variable to unsigned.

And why is that an improvement?

Regards,
Christian.

Quoted 42 lines
---
   drivers/gpu/drm/amd/amdgpu/imu_v12_0.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -1
index 0c8ef908d112..2d6f7549c2af 100644
@@ -119,7 +119,7 @@ static int imu_v12_0_load_microcode(struct
 amdgpu_device *adev)
 
   static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)
   {
-     int i, imu_reg_val = 0;
+     unsigned int i, imu_reg_val = 0;
 
       for (i = 0; i < adev->usec_timeout; i++) {
               imu_reg_val = RREG32_SOC15(GC, 0,

regGFX_IMU_GFX_RESET_CTRL); @@
-138,7 +138,7 @@ static int imu_v12_0_wait_for_reset_status(struct amdgpu_device *adev)

   static void imu_v12_0_setup(struct amdgpu_device *adev)
   {
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -1
-     int imu_reg_val;
+     unsigned int imu_reg_val;
 
       WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL0, 0xffffff);
       WREG32_SOC15(GC, 0, regGFX_IMU_C2PMSG_ACCESS_CTRL1, 0xffff);

@@
-157,7 +157,7 @@ static void imu_v12_0_setup(struct amdgpu_device *adev)

   static int imu_v12_0_start(struct amdgpu_device *adev)
   {
drivers/gpu/drm/amd/amdgpu/imu_v12_0.c +1 -1
-     int imu_reg_val;
+     unsigned int imu_reg_val;
 
       imu_reg_val = RREG32_SOC15(GC, 0, regGFX_IMU_CORE_CTRL);
       imu_reg_val &= 0xfffffffe;