Skip to contentSkip to conversation

drm/amdgpu: fix uninitialized variable warning

PATCH In review Bob Zhou 2 participants 6 messages Apr 23, 2024

Subsystems (2)
lore
Share & tools
lore

Bob Zhou

author
#0 lore raw

PATCH 2/2 drm/amdgpu: fix uninitialized variable warning

Because the val isn't initialized, a random variable is set by amdgpu_i2c_put_byte. So fix the uninitialized issue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +1 -1
index 82608df43396..d4d2dc792b60 100644
@@ -368,7 +368,7 @@ amdgpu_i2c_router_select_ddc_port(const struct amdgpu_connector *amdgpu_connecto
 void
 amdgpu_i2c_router_select_cd_port(const struct amdgpu_connector *amdgpu_connector)
 {
-	u8 val;
+	u8 val = 0;
 
 	if (!amdgpu_connector->router.cd_valid)
 		return;
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Am 23.04.24 um 07:33 schrieb Bob Zhou:

Quoted 2 lines

Because the val isn't initialized, a random variable is set by amdgpu_i2c_put_byte. So fix the uninitialized issue.

Well that isn't correct. See the code here:

        amdgpu_i2c_get_byte(amdgpu_connector->router_bus, amdgpu_connector->router.i2c_addr, 0x3, &val);
        val &= ~amdgpu_connector->router.cd_mux_control_pin; amdgpu_i2c_put_byte(amdgpu_connector->router_bus, amdgpu_connector->router.i2c_addr, 0x3, val);

The value is first read by amdgpu_i2c_get_byte(), then modified and then written again by amdgpu_i2c_put_byte().

Was this an automated warning?

Either way the patch is clearly rejected.

Regards,
Christian.

Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +1 -1
index 82608df43396..d4d2dc792b60 100644
@@ -368,7 +368,7 @@ amdgpu_i2c_router_select_ddc_port(const struct amdgpu_connector *amdgpu_connecto
  void
  amdgpu_i2c_router_select_cd_port(const struct amdgpu_connector *amdgpu_connector)
  {
-	u8 val;
+	u8 val = 0;
 
  	if (!amdgpu_connector->router.cd_valid)
  		return;
author
#2 lore raw

[AMD Official Use Only - General]

Thanks for your comments.

I should clarify the issue. As you see the amdgpu_i2c_get_byte code:

                if (i2c_transfer(&i2c_bus->adapter, msgs, 2) == 2) {
                        *val = in_buf[0];
                        DRM_DEBUG("val = 0x%02x\n", *val);
                } else {
                        DRM_DEBUG("i2c 0x%02x 0x%02x read failed\n",  addr, *val);
                }

If the read failure by amdgpu_i2c_get_byte(), the value will not be modified.
Then the amdgpu_i2c_put_byte() successfully written the random value and it will cause unexpected issue.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年4月23日 14:05
To: Zhou, Bob <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: fix uninitialized variable warning

Am 23.04.24 um 07:33 schrieb Bob Zhou:

Quoted 2 lines

Because the val isn't initialized, a random variable is set by amdgpu_i2c_put_byte. So fix the uninitialized issue.

Well that isn't correct. See the code here:

         amdgpu_i2c_get_byte(amdgpu_connector->router_bus,
                             amdgpu_connector->router.i2c_addr,
                             0x3, &val);
         val &= ~amdgpu_connector->router.cd_mux_control_pin;
         amdgpu_i2c_put_byte(amdgpu_connector->router_bus,
                             amdgpu_connector->router.i2c_addr,
                             0x3, val);

The value is first read by amdgpu_i2c_get_byte(), then modified and then written again by amdgpu_i2c_put_byte().

Was this an automated warning?

Either way the patch is clearly rejected.

Regards,
Christian.

Quoted 20 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +1 -1
index 82608df43396..d4d2dc792b60 100644
@@ -368,7 +368,7 @@ amdgpu_i2c_router_select_ddc_port(const struct amdgpu_connector *amdgpu_connecto
  void
  amdgpu_i2c_router_select_cd_port(const struct amdgpu_connector *amdgpu_connector)
  {
-     u8 val;
+     u8 val = 0;
 
      if (!amdgpu_connector->router.cd_valid)
              return;
maintainer
#3 lore raw

In this case we should modify amdgpu_i2c_get_byte() to return an error and prevent writing the value back.

See zero is as random as any other value and initializing the variable here doesn't really help, it just makes your warning disappear.

Regards,
Christian.

Am 23.04.24 um 08:27 schrieb Zhou, Bob:

Quoted 64 lines

[AMD Official Use Only - General]

Thanks for your comments.

I should clarify the issue. As you see the amdgpu_i2c_get_byte code:

                 if (i2c_transfer(&i2c_bus->adapter, msgs, 2) == 2) {
                         *val = in_buf[0];
                         DRM_DEBUG("val = 0x%02x\n", *val);
                 } else {
                         DRM_DEBUG("i2c 0x%02x 0x%02x read failed\n",  addr, *val);
                 }

If the read failure by amdgpu_i2c_get_byte(), the value will not be modified.
Then the amdgpu_i2c_put_byte() successfully written the random value and it will cause unexpected issue.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年4月23日 14:05
To: Zhou, Bob <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: fix uninitialized variable warning

Am 23.04.24 um 07:33 schrieb Bob Zhou:

Quoted 2 lines

Because the val isn't initialized, a random variable is set by amdgpu_i2c_put_byte. So fix the uninitialized issue.

Well that isn't correct. See the code here:

          amdgpu_i2c_get_byte(amdgpu_connector->router_bus,
                              amdgpu_connector->router.i2c_addr,
                              0x3, &val);
          val &= ~amdgpu_connector->router.cd_mux_control_pin;
          amdgpu_i2c_put_byte(amdgpu_connector->router_bus,
                              amdgpu_connector->router.i2c_addr,
                              0x3, val);

The value is first read by amdgpu_i2c_get_byte(), then modified and then written again by amdgpu_i2c_put_byte().

Was this an automated warning?

Either way the patch is clearly rejected.

Regards,
Christian.

Quoted 19 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +1 -1
index 82608df43396..d4d2dc792b60 100644
@@ -368,7 +368,7 @@ amdgpu_i2c_router_select_ddc_port(const struct amdgpu_connector *amdgpu_connecto
   void
   amdgpu_i2c_router_select_cd_port(const struct amdgpu_connector *amdgpu_connector)
   {
-     u8 val;
+     u8 val = 0;
 
       if (!amdgpu_connector->router.cd_valid)
               return;
author
#4 lore raw

[AMD Official Use Only - General]

Hi Christian

Agree with you, returning an error is surely a better modification. I will send v2 patch to fix this.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年4月23日 15:41
To: Zhou, Bob <[email protected]>; Koenig, Christian <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: fix uninitialized variable warning

In this case we should modify amdgpu_i2c_get_byte() to return an error and prevent writing the value back.

See zero is as random as any other value and initializing the variable here doesn't really help, it just makes your warning disappear.

Regards,
Christian.

Am 23.04.24 um 08:27 schrieb Zhou, Bob:

Quoted 67 lines

[AMD Official Use Only - General]

Thanks for your comments.

I should clarify the issue. As you see the amdgpu_i2c_get_byte code:

                 if (i2c_transfer(&i2c_bus->adapter, msgs, 2) == 2) {
                         *val = in_buf[0];
                         DRM_DEBUG("val = 0x%02x\n", *val);
                 } else {
                         DRM_DEBUG("i2c 0x%02x 0x%02x read failed\n",  addr, *val);
                 }

If the read failure by amdgpu_i2c_get_byte(), the value will not be modified.
Then the amdgpu_i2c_put_byte() successfully written the random value and it will cause unexpected issue.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年4月23日 14:05
To: Zhou, Bob <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: fix uninitialized variable warning

Am 23.04.24 um 07:33 schrieb Bob Zhou:

Quoted 2 lines

Because the val isn't initialized, a random variable is set by amdgpu_i2c_put_byte. So fix the uninitialized issue.

Well that isn't correct. See the code here:

          amdgpu_i2c_get_byte(amdgpu_connector->router_bus,
                              amdgpu_connector->router.i2c_addr,
                              0x3, &val);
          val &= ~amdgpu_connector->router.cd_mux_control_pin;
          amdgpu_i2c_put_byte(amdgpu_connector->router_bus,
                              amdgpu_connector->router.i2c_addr,
                              0x3, val);

The value is first read by amdgpu_i2c_get_byte(), then modified and then written again by amdgpu_i2c_put_byte().

Was this an automated warning?

Either way the patch is clearly rejected.

Regards,
Christian.

Quoted 19 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +1 -1
index 82608df43396..d4d2dc792b60 100644
@@ -368,7 +368,7 @@ amdgpu_i2c_router_select_ddc_port(const struct amdgpu_connector *amdgpu_connecto
   void
   amdgpu_i2c_router_select_cd_port(const struct amdgpu_connector *amdgpu_connector)
   {
-     u8 val;
+     u8 val = 0;
 
       if (!amdgpu_connector->router.cd_valid)
               return;
author
#5 lore raw
In reply to Christian König

[Public]

Thanks for your comments.

I should clarify the issue. As you see the amdgpu_i2c_get_byte code:

                if (i2c_transfer(&i2c_bus->adapter, msgs, 2) == 2) {
                        *val = in_buf[0];
                        DRM_DEBUG("val = 0x%02x\n", *val);
                } else {
                        DRM_DEBUG("i2c 0x%02x 0x%02x read failed\n",  addr, *val);
                }

If the read failure by amdgpu_i2c_get_byte(), the value will not be modified.
Then the amdgpu_i2c_put_byte() successfully written the random value and it will cause unexpected issue.

Regards,
Bob

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: 2024年4月23日 14:05
To: Zhou, Bob <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: fix uninitialized variable warning

Am 23.04.24 um 07:33 schrieb Bob Zhou:

Quoted 2 lines

Because the val isn't initialized, a random variable is set by amdgpu_i2c_put_byte. So fix the uninitialized issue.

Well that isn't correct. See the code here:

         amdgpu_i2c_get_byte(amdgpu_connector->router_bus,
                             amdgpu_connector->router.i2c_addr,
                             0x3, &val);
         val &= ~amdgpu_connector->router.cd_mux_control_pin;
         amdgpu_i2c_put_byte(amdgpu_connector->router_bus,
                             amdgpu_connector->router.i2c_addr,
                             0x3, val);

The value is first read by amdgpu_i2c_get_byte(), then modified and then written again by amdgpu_i2c_put_byte().

Was this an automated warning?

Either way the patch is clearly rejected.

Regards,
Christian.

Quoted 20 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +1 -1
index 82608df43396..d4d2dc792b60 100644
@@ -368,7 +368,7 @@ amdgpu_i2c_router_select_ddc_port(const struct amdgpu_connector *amdgpu_connecto
  void
  amdgpu_i2c_router_select_cd_port(const struct amdgpu_connector *amdgpu_connector)
  {
-     u8 val;
+     u8 val = 0;
 
      if (!amdgpu_connector->router.cd_valid)
              return;