Skip to contentSkip to conversation

drm/amdgpu: fix overflowed constant warning in mmhub_set_clockgating()

PATCH In review Bob Zhou 2 participants 4 messages Jun 7, 2024

Subsystems (2)
lore
Share & tools
lore

Bob Zhou

author
#0 lore raw

PATCH 1/2 drm/amdgpu: fix overflowed constant warning in mmhub_set_clockgating()

To fix potential overflowed constant warning, modify the variables to u32 for getting the return value of RREG32_SOC15().

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c +1 -1
index 92432cd2c0c7..9689e2b5d4e5 100644
@@ -544,7 +544,7 @@ static int mmhub_v1_7_set_clockgating(struct amdgpu_device *adev,
 
 static void mmhub_v1_7_get_clockgating(struct amdgpu_device *adev, u64 *flags)
 {
-	int data, data1;
+	u32 data, data1;
 
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +1 -1
index 02fd45261399..a0cc8e218ca1 100644
@@ -671,7 +671,7 @@ static int mmhub_v2_0_set_clockgating(struct amdgpu_device *adev,
 
 static void mmhub_v2_0_get_clockgating(struct amdgpu_device *adev, u64 *flags)
 {
-	int data, data1;
+	u32 data, data1;
 
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c +1 -1
index 8928f9160822..b4ce3375d3fd 100644
@@ -613,7 +613,7 @@ static int mmhub_v3_3_set_clockgating(struct amdgpu_device *adev,
 
 static void mmhub_v3_3_get_clockgating(struct amdgpu_device *adev, u64 *flags)
 {
-	int data;
+	u32 data;
 
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c +1 -1
index 1b7da4aff2b8..ff1b58e44689 100644
@@ -657,7 +657,7 @@ static int mmhub_v9_4_set_clockgating(struct amdgpu_device *adev,
 
 static void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u64 *flags)
 {
-	int data, data1;
+	u32 data, data1;
 
 	if (amdgpu_sriov_vf(adev))
 		*flags = 0;
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/2 drm/amdgpu: fix dereferencing null pointer warning in ring_test_ib()

To avoid null pointer dereference, Check return value and conduct error handling.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 4 ++++
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 4 ++++
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 4 ++++
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 4 ++++
 6 files changed, 20 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -0
index 2a510351dfce..f131f96a734c 100644
@@ -547,6 +547,8 @@ static int gfx_v11_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, padding);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, padding);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = cpu_to_le32(0xCAFEDEAD);
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2 -0
index 460bf33a22b1..b5719760abe2 100644
@@ -322,6 +322,8 @@ static int gfx_v12_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, padding);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, padding);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = cpu_to_le32(0xCAFEDEAD);
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +4 -0
index b7d33d78bce0..56edac57d1e3 100644
@@ -984,6 +984,8 @@ static int sdma_v5_0_ring_test_ring(struct amdgpu_ring *ring)
 					 AMDGPU_MES_CTX_PADDING_OFFS);
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = tmp;
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
@@ -1067,6 +1069,8 @@ static int sdma_v5_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 					 AMDGPU_MES_CTX_PADDING_OFFS);
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = tmp;
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +4 -0
index cc9e961f0078..3e5316a24c90 100644
@@ -824,6 +824,8 @@ static int sdma_v5_2_ring_test_ring(struct amdgpu_ring *ring)
 					 AMDGPU_MES_CTX_PADDING_OFFS);
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = tmp;
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
@@ -907,6 +909,8 @@ static int sdma_v5_2_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 					 AMDGPU_MES_CTX_PADDING_OFFS);
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = tmp;
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +4 -0
index c833b6b8373b..c1d6ece57bd4 100644
@@ -846,6 +846,8 @@ static int sdma_v6_0_ring_test_ring(struct amdgpu_ring *ring)
 					 AMDGPU_MES_CTX_PADDING_OFFS);
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = tmp;
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
@@ -929,6 +931,8 @@ static int sdma_v6_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 					 AMDGPU_MES_CTX_PADDING_OFFS);
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = tmp;
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +4 -0
index 96514fd77e35..2ea988e7e242 100644
@@ -859,6 +859,8 @@ static int sdma_v7_0_ring_test_ring(struct amdgpu_ring *ring)
 					 AMDGPU_MES_CTX_PADDING_OFFS);
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = tmp;
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
@@ -942,6 +944,8 @@ static int sdma_v7_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 					 AMDGPU_MES_CTX_PADDING_OFFS);
 		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
 		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
 		*cpu_ptr = tmp;
 	} else {
 		r = amdgpu_device_wb_get(adev, &index);
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: fix dereferencing null pointer warning in ring_test_ib()

Am 07.06.24 um 10:33 schrieb Bob Zhou:

Quoted 2 lines

To avoid null pointer dereference, Check return value and conduct error handling.

That doesn't make much sense.

At this point the amdgpu_mes_ctx_get_offs_cpu_addr() shouldn't be able to return NULL in the first place.

Regards,
Christian.

Quoted 125 lines
---
  drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 ++
  drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 ++
  drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 4 ++++
  drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 4 ++++
  drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 4 ++++
  drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 4 ++++
  6 files changed, 20 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -0
index 2a510351dfce..f131f96a734c 100644
@@ -547,6 +547,8 @@ static int gfx_v11_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, padding);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, padding);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = cpu_to_le32(0xCAFEDEAD);
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2 -0
index 460bf33a22b1..b5719760abe2 100644
@@ -322,6 +322,8 @@ static int gfx_v12_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, padding);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, padding);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = cpu_to_le32(0xCAFEDEAD);
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +4 -0
index b7d33d78bce0..56edac57d1e3 100644
@@ -984,6 +984,8 @@ static int sdma_v5_0_ring_test_ring(struct amdgpu_ring *ring)
  					 AMDGPU_MES_CTX_PADDING_OFFS);
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = tmp;
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
@@ -1067,6 +1069,8 @@ static int sdma_v5_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
  					 AMDGPU_MES_CTX_PADDING_OFFS);
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = tmp;
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +4 -0
index cc9e961f0078..3e5316a24c90 100644
@@ -824,6 +824,8 @@ static int sdma_v5_2_ring_test_ring(struct amdgpu_ring *ring)
  					 AMDGPU_MES_CTX_PADDING_OFFS);
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = tmp;
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
@@ -907,6 +909,8 @@ static int sdma_v5_2_ring_test_ib(struct amdgpu_ring *ring, long timeout)
  					 AMDGPU_MES_CTX_PADDING_OFFS);
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = tmp;
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +4 -0
index c833b6b8373b..c1d6ece57bd4 100644
@@ -846,6 +846,8 @@ static int sdma_v6_0_ring_test_ring(struct amdgpu_ring *ring)
  					 AMDGPU_MES_CTX_PADDING_OFFS);
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = tmp;
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
@@ -929,6 +931,8 @@ static int sdma_v6_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
  					 AMDGPU_MES_CTX_PADDING_OFFS);
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = tmp;
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +4 -0
index 96514fd77e35..2ea988e7e242 100644
@@ -859,6 +859,8 @@ static int sdma_v7_0_ring_test_ring(struct amdgpu_ring *ring)
  					 AMDGPU_MES_CTX_PADDING_OFFS);
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = tmp;
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
@@ -942,6 +944,8 @@ static int sdma_v7_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
  					 AMDGPU_MES_CTX_PADDING_OFFS);
  		gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
  		cpu_ptr = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+		if (cpu_ptr == NULL)
+			return -EINVAL;
  		*cpu_ptr = tmp;
  	} else {
  		r = amdgpu_device_wb_get(adev, &index);
maintainer Acked-by on v1 1/2
#3 lore raw
In reply to Bob Zhou

Am 07.06.24 um 10:33 schrieb Bob Zhou:

Quoted 4 lines

To fix potential overflowed constant warning, modify the variables to u32 for getting the return value of RREG32_SOC15().

Quoted 59 lines
---
  drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c | 2 +-
  drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 2 +-
  4 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c +1 -1
index 92432cd2c0c7..9689e2b5d4e5 100644
@@ -544,7 +544,7 @@ static int mmhub_v1_7_set_clockgating(struct amdgpu_device *adev,
 
  static void mmhub_v1_7_get_clockgating(struct amdgpu_device *adev, u64 *flags)
  {
-	int data, data1;
+	u32 data, data1;
 
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +1 -1
index 02fd45261399..a0cc8e218ca1 100644
@@ -671,7 +671,7 @@ static int mmhub_v2_0_set_clockgating(struct amdgpu_device *adev,
 
  static void mmhub_v2_0_get_clockgating(struct amdgpu_device *adev, u64 *flags)
  {
-	int data, data1;
+	u32 data, data1;
 
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c +1 -1
index 8928f9160822..b4ce3375d3fd 100644
@@ -613,7 +613,7 @@ static int mmhub_v3_3_set_clockgating(struct amdgpu_device *adev,
 
  static void mmhub_v3_3_get_clockgating(struct amdgpu_device *adev, u64 *flags)
  {
-	int data;
+	u32 data;
 
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;
drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c +1 -1
index 1b7da4aff2b8..ff1b58e44689 100644
@@ -657,7 +657,7 @@ static int mmhub_v9_4_set_clockgating(struct amdgpu_device *adev,
 
  static void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u64 *flags)
  {
-	int data, data1;
+	u32 data, data1;
 
  	if (amdgpu_sriov_vf(adev))
  		*flags = 0;