From: Bob Zhou <bob.zhou@amd.com>
To: <amd-gfx@lists.freedesktop.org>, <Tim.Huang@amd.com>,
<jesse.zhang@amd.com>
Cc: <alexander.deucher@amd.com>, <christian.koenig@amd.com>,
Bob Zhou <bob.zhou@amd.com>
Subject: [PATCH 2/2] drm/amdgpu: fix dereferencing null pointer warning in ring_test_ib()
Date: Fri, 7 Jun 2024 16:33:36 +0800 [thread overview]
Message-ID: <20240607083336.65752-2-bob.zhou@amd.com> (raw)
In-Reply-To: <20240607083336.65752-1-bob.zhou@amd.com>
To avoid null pointer dereference, Check return value and
conduct error handling.
Signed-off-by: Bob Zhou <bob.zhou@amd.com>
---
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(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 2a510351dfce..f131f96a734c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
index 460bf33a22b1..b5719760abe2 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
index b7d33d78bce0..56edac57d1e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
index cc9e961f0078..3e5316a24c90 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
index c833b6b8373b..c1d6ece57bd4 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
index 96514fd77e35..2ea988e7e242 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
@@ -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);
--
2.34.1
next prev parent reply other threads:[~2024-06-07 8:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-07 8:33 [PATCH 1/2] drm/amdgpu: fix overflowed constant warning in mmhub_set_clockgating() Bob Zhou
2024-06-07 8:33 ` Bob Zhou [this message]
2024-06-07 11:39 ` [PATCH 2/2] drm/amdgpu: fix dereferencing null pointer warning in ring_test_ib() Christian König
2024-06-07 11:38 ` [PATCH 1/2] drm/amdgpu: fix overflowed constant warning in mmhub_set_clockgating() Christian König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240607083336.65752-2-bob.zhou@amd.com \
--to=bob.zhou@amd.com \
--cc=Tim.Huang@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=jesse.zhang@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox