Skip to contentSkip to conversation

drm/amdgpu/vcn: fix unitialized variable warnings

PATCH Superseded Pierre-Eric Pelloux-Prayer 3 participants 3 messages Apr 18, 2024 – Apr 19, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu/vcn: fix unitialized variable warnings

Init r to 0 to avoid returning an uninitialized value if we never enter the loop. This case should never be hit in practive, but returning 0 doesn't hurt.

The same fix is applied to the 4 places using the same pattern.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1 -1
index 8f82fb887e9c..724445545563 100644
@@ -298,7 +298,7 @@ static int vcn_v3_0_hw_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct amdgpu_ring *ring;
-	int i, j, r;
+	int i, j, r = 0;
 
 	if (amdgpu_sriov_vf(adev)) {
 		r = vcn_v3_0_start_sriov(adev);
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -1
index 832d15f7b5f6..9be7ae7af4b1 100644
@@ -253,7 +253,7 @@ static int vcn_v4_0_hw_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct amdgpu_ring *ring;
-	int i, r;
+	int i, r = 0;
 
 	if (amdgpu_sriov_vf(adev)) {
 		r = vcn_v4_0_start_sriov(adev);
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1 -1
index 501e53e69f2a..593c64e4b8ef 100644
@@ -221,7 +221,7 @@ static int vcn_v4_0_5_hw_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct amdgpu_ring *ring;
-	int i, r;
+	int i, r = 0;
 
 	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
 		if (adev->vcn.harvest_config & (1 << i))
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1 -1
index bc60c554eb32..246f967e2e7d 100644
@@ -187,7 +187,7 @@ static int vcn_v5_0_0_hw_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct amdgpu_ring *ring;
-	int i, r;
+	int i, r = 0;
 
 	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
 		if (adev->vcn.harvest_config & (1 << i))
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Pierre-Eric Pelloux-Prayer

Init r to 0 to avoid returning an uninitialized value if we never enter the loop. This case should never be hit in practive, but

s/practive/practice/

Quoted 1 line

returning 0 doesn't hurt.

s/returning/initializing to/

With that fixed,

Quoted 66 lines

The same fix is applied to the 4 places using the same pattern.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1 -1
index 8f82fb887e9c..724445545563 100644
@@ -298,7 +298,7 @@ static int vcn_v3_0_hw_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct amdgpu_ring *ring;
-       int i, j, r;
+       int i, j, r = 0;
 
        if (amdgpu_sriov_vf(adev)) {
                r = vcn_v3_0_start_sriov(adev);
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -1
index 832d15f7b5f6..9be7ae7af4b1 100644
@@ -253,7 +253,7 @@ static int vcn_v4_0_hw_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct amdgpu_ring *ring;
-       int i, r;
+       int i, r = 0;
 
        if (amdgpu_sriov_vf(adev)) {
                r = vcn_v4_0_start_sriov(adev);
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1 -1
index 501e53e69f2a..593c64e4b8ef 100644
@@ -221,7 +221,7 @@ static int vcn_v4_0_5_hw_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct amdgpu_ring *ring;
-       int i, r;
+       int i, r = 0;
 
        for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
                if (adev->vcn.harvest_config & (1 << i))
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1 -2
index bc60c554eb32..246f967e2e7d 100644
@@ -187,7 +187,7 @@ static int vcn_v5_0_0_hw_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        struct amdgpu_ring *ring;
-       int i, r;
+       int i, r = 0;
 
        for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
                if (adev->vcn.harvest_config & (1 << i))
--

2.41.0

#2 lore raw
In reply to Pierre-Eric Pelloux-Prayer

Am 18.04.24 um 20:07 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 19 lines

Init r to 0 to avoid returning an uninitialized value if we never enter the loop. This case should never be hit in practive, but returning 0 doesn't hurt.

The same fix is applied to the 4 places using the same pattern.

---
  drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c   | 2 +-
  drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 2 +-
  drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 2 +-
  4 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0 -0
index 8f82fb887e9c..724445545563 100644

drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c static int vcn_v3_0_hw_init(void *handle) · line 301

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1 -1
@@ -298,7 +298,7 @@ static int vcn_v3_0_hw_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct amdgpu_ring *ring;
-	int i, j, r;
+	int i, j, r = 0;

That is usually considered bad coding style.

Better insert a "return 0;" directly before the done label.

Regards,
Christian.

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0 -0
  	if (amdgpu_sriov_vf(adev)) {
  		r = vcn_v3_0_start_sriov(adev);
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -1
index 832d15f7b5f6..9be7ae7af4b1 100644
@@ -253,7 +253,7 @@ static int vcn_v4_0_hw_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct amdgpu_ring *ring;
-	int i, r;
+	int i, r = 0;
 
  	if (amdgpu_sriov_vf(adev)) {
  		r = vcn_v4_0_start_sriov(adev);
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1 -1
index 501e53e69f2a..593c64e4b8ef 100644
@@ -221,7 +221,7 @@ static int vcn_v4_0_5_hw_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct amdgpu_ring *ring;
-	int i, r;
+	int i, r = 0;
 
  	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
  		if (adev->vcn.harvest_config & (1 << i))
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1 -1
index bc60c554eb32..246f967e2e7d 100644
@@ -187,7 +187,7 @@ static int vcn_v5_0_0_hw_init(void *handle)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct amdgpu_ring *ring;
-	int i, r;
+	int i, r = 0;
 
  	for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
  		if (adev->vcn.harvest_config & (1 << i))