Skip to contentSkip to conversation

drm/amdgpu: Fix uninitialized variable warning in amdgpu_afmt_acr

PATCH Superseded Ma Jun 3 participants 6 messages Apr 24, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ma Jun

author
#0 lore raw

PATCH 1/3 drm/amdgpu: Fix uninitialized variable warning in amdgpu_afmt_acr

Assign value to clock to fix the warning below:
"Using uninitialized value res. Field res.clock is uninitialized"

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c +2 -1
index a4d65973bf7c..9e3442b2d2ec 100644
@@ -87,7 +87,7 @@ static void amdgpu_afmt_calc_cts(uint32_t clock, int *CTS, int *N, int freq)
 
 struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock)
 {
-	struct amdgpu_afmt_acr res;
+	struct amdgpu_afmt_acr res = {0};
 	u8 i;
 
 	/* Precalculated values for common clocks */
@@ -100,6 +100,7 @@ struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock)
 	amdgpu_afmt_calc_cts(clock, &res.cts_32khz, &res.n_32khz, 32000);
 	amdgpu_afmt_calc_cts(clock, &res.cts_44_1khz, &res.n_44_1khz, 44100);
 	amdgpu_afmt_calc_cts(clock, &res.cts_48khz, &res.n_48khz, 48000);
+	res.clock = clock;
 
 	return res;
 }
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/3 drm/amdgpu: Initialize timestamp for some legacy SOCs

Initialize the interrupt timestamp for some legacy SOCs to fix the coverity issue "Uninitialized scalar variable"

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +8 -0
index 7e6d09730e6d..665c63f55278 100644
@@ -445,6 +445,14 @@ void amdgpu_irq_dispatch(struct amdgpu_device *adev,
 
 	entry.ih = ih;
 	entry.iv_entry = (const uint32_t *)&ih->ring[ring_index];
+
+	/*
+	 * timestamp is not supported on some legacy SOCs (cik, cz, iceland,
+	 * si and tonga), so initialize timestamp and timestamp_src to 0
+	 */
+	entry.timestamp = 0;
+	entry.timestamp_src = 0;
+
 	amdgpu_ih_decode_iv(adev, &entry);
 
 	trace_amdgpu_iv(ih - &adev->irq.ih, &entry);
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] drm/amdgpu: Initialize timestamp for some legacy SOCs

Am 24.04.24 um 12:03 schrieb Ma Jun:

Quoted 5 lines

Initialize the interrupt timestamp for some legacy SOCs to fix the coverity issue "Uninitialized scalar variable"

Quoted 23 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +8 -0
index 7e6d09730e6d..665c63f55278 100644
@@ -445,6 +445,14 @@ void amdgpu_irq_dispatch(struct amdgpu_device *adev,
 
  	entry.ih = ih;
  	entry.iv_entry = (const uint32_t *)&ih->ring[ring_index];
+
+	/*
+	 * timestamp is not supported on some legacy SOCs (cik, cz, iceland,
+	 * si and tonga), so initialize timestamp and timestamp_src to 0
+	 */
+	entry.timestamp = 0;
+	entry.timestamp_src = 0;
+
  	amdgpu_ih_decode_iv(adev, &entry);
 
  	trace_amdgpu_iv(ih - &adev->irq.ih, &entry);
author
#3 lore raw

PATCH 3/3 drm/amdgpu: Fix the uninitialized variable warning

In reply to Ma Jun

Initialize the phy_id to 0 to fix the warning of
"Using uninitialized value phy_id"

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +1 -1
index 8ed0e073656f..df81078aa26d 100644
@@ -95,7 +95,7 @@ static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u
 	struct psp_context *psp = &adev->psp;
 	struct ta_securedisplay_cmd *securedisplay_cmd;
 	struct drm_device *dev = adev_to_drm(adev);
-	uint32_t phy_id;
+	uint32_t phy_id = 0;
 	uint32_t op;
 	char str[64];
 	int ret;
Signature · 1 line
2.34.1
#4 lore raw

RE: [PATCH 3/3] drm/amdgpu: Fix the uninitialized variable warning

[AMD Official Use Only - General]

Quoted 26 lines

-----Original Message-----
From: Ma, Jun <[email protected]>
Sent: Wednesday, April 24, 2024 6:04 AM
To: [email protected]; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>
Cc: Ma, Jun <[email protected]>
Subject: [PATCH 3/3] drm/amdgpu: Fix the uninitialized variable warning

Initialize the phy_id to 0 to fix the warning of "Using uninitialized value phy_id"

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +0 -0
index 8ed0e073656f..df81078aa26d 100644
@@ -95,7 +95,7 @@ static ssize_t

amdgpu_securedisplay_debugfs_write(struct file *f, const char __u

      struct psp_context *psp = &adev->psp;
      struct ta_securedisplay_cmd *securedisplay_cmd;
      struct drm_device *dev = adev_to_drm(adev);

drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c static ssize_t amdgpu_securedisplay_debugfs_write(struct file *f, const char __u · line 98

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_securedisplay.c +1 -1
-     uint32_t phy_id;
+     uint32_t phy_id = 0;

Would be better to return an error in case 2: below if size < 3. Otherwise we are just blindly using 0 for phy id.

Alex

Quoted 5 lines
      uint32_t op;
      char str[64];
      int ret;

--
2.34.1

#5 lore raw
In reply to Ma Jun

[AMD Official Use Only - General]

Quoted 24 lines

-----Original Message-----
From: Ma, Jun <[email protected]>
Sent: Wednesday, April 24, 2024 6:04 AM
To: [email protected]; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>
Cc: Ma, Jun <[email protected]>
Subject: [PATCH 1/3] drm/amdgpu: Fix uninitialized variable warning in amdgpu_afmt_acr

Assign value to clock to fix the warning below:
"Using uninitialized value res. Field res.clock is uninitialized"

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c +0 -0
index a4d65973bf7c..9e3442b2d2ec 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c static void amdgpu_afmt_calc_cts(uint32_t clock, int · line 90

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c +1 -1
@@ -87,7 +87,7 @@ static void amdgpu_afmt_calc_cts(uint32_t clock, int
 *CTS, int *N, int freq)
 
 struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock)  {
-     struct amdgpu_afmt_acr res;
+     struct amdgpu_afmt_acr res = {0};

I think you can drop this hunk since all of the fields are initialized below.

Alex

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_afmt.c +0 -0
      u8 i;
 
      /* Precalculated values for common clocks */ @@ -100,6 +100,7 @@

struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock)

      amdgpu_afmt_calc_cts(clock, &res.cts_32khz, &res.n_32khz, 32000);
      amdgpu_afmt_calc_cts(clock, &res.cts_44_1khz, &res.n_44_1khz,
44100);
      amdgpu_afmt_calc_cts(clock, &res.cts_48khz, &res.n_48khz, 48000);

+ res.clock = clock;

      return res;

}
--
2.34.1