From: Sunil Khatri <sunil.khatri@amd.com>
To: "Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>
Cc: amd-gfx@lists.freedesktop.org, Sunil Khatri <sunil.khatri@amd.com>
Subject: [PATCH v3 16/16] drm/amdgpu: validate hw_init function pointers
Date: Wed, 16 Oct 2024 12:52:58 +0530 [thread overview]
Message-ID: <20241016072258.1399698-17-sunil.khatri@amd.com> (raw)
In-Reply-To: <20241016072258.1399698-1-sunil.khatri@amd.com>
Validate function pointer at all the places where
hw_init is called to avoid a NULL dereference.
Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 82 ++++++++++++++--------
1 file changed, 51 insertions(+), 31 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index b9ca5b1cde0c..4142acc36796 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2687,11 +2687,13 @@ static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
(amdgpu_sriov_vf(adev) && (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP)) ||
adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH) {
- r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
- if (r) {
- DRM_ERROR("hw_init of IP block <%s> failed %d\n",
- adev->ip_blocks[i].version->funcs->name, r);
- return r;
+ if (adev->ip_blocks[i].version->funcs->hw_init) {
+ r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
+ if (r) {
+ DRM_ERROR("hw_init of IP block <%s> failed %d\n",
+ adev->ip_blocks[i].version->funcs->name, r);
+ return r;
+ }
}
adev->ip_blocks[i].status.hw = true;
}
@@ -2712,11 +2714,13 @@ static int amdgpu_device_ip_hw_init_phase2(struct amdgpu_device *adev)
if (!amdgpu_ip_member_of_hwini(
adev, adev->ip_blocks[i].version->type))
continue;
- r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
- if (r) {
- DRM_ERROR("hw_init of IP block <%s> failed %d\n",
- adev->ip_blocks[i].version->funcs->name, r);
- return r;
+ if (adev->ip_blocks[i].version->funcs->hw_init) {
+ r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
+ if (r) {
+ DRM_ERROR("hw_init of IP block <%s> failed %d\n",
+ adev->ip_blocks[i].version->funcs->name, r);
+ return r;
+ }
}
adev->ip_blocks[i].status.hw = true;
}
@@ -2758,11 +2762,15 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)
}
}
} else {
- r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
- if (r) {
- DRM_ERROR("hw_init of IP block <%s> failed %d\n",
- adev->ip_blocks[i].version->funcs->name, r);
- return r;
+ if (adev->ip_blocks[i].version->funcs->hw_init) {
+ r = adev->ip_blocks[i].version->funcs
+ ->hw_init(&adev->ip_blocks[i]);
+ if (r) {
+ DRM_ERROR("hw_init of IP block <%s> failed %d\n",
+ adev->ip_blocks[i].version->funcs->name,
+ r);
+ return r;
+ }
}
}
@@ -2873,11 +2881,17 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
continue;
if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
- /* need to do common hw init early so everything is set up for gmc */
- r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
- if (r) {
- DRM_ERROR("hw_init %d failed %d\n", i, r);
- goto init_failed;
+ if (adev->ip_blocks[i].version->funcs->hw_init) {
+ /*
+ * need to do common hw init early so everything
+ * is set up for gmc.
+ */
+ r = adev->ip_blocks[i].version->funcs
+ ->hw_init(&adev->ip_blocks[i]);
+ if (r) {
+ DRM_ERROR("hw_init %d failed %d\n", i, r);
+ goto init_failed;
+ }
}
adev->ip_blocks[i].status.hw = true;
} else if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
@@ -2891,10 +2905,12 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
DRM_ERROR("amdgpu_mem_scratch_init failed %d\n", r);
goto init_failed;
}
- r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
- if (r) {
- DRM_ERROR("hw_init %d failed %d\n", i, r);
- goto init_failed;
+ if (adev->ip_blocks[i].version->funcs->hw_init) {
+ r = adev->ip_blocks[i].version->funcs->hw_init(&adev->ip_blocks[i]);
+ if (r) {
+ DRM_ERROR("hw_init %d failed %d\n", i, r);
+ goto init_failed;
+ }
}
r = amdgpu_device_wb_init(adev);
if (r) {
@@ -3643,11 +3659,13 @@ static int amdgpu_device_ip_reinit_early_sriov(struct amdgpu_device *adev)
if (block->version->type != ip_order[j] ||
!block->status.valid)
continue;
-
- r = block->version->funcs->hw_init(&adev->ip_blocks[i]);
- DRM_INFO("RE-INIT-early: %s %s\n", block->version->funcs->name, r?"failed":"succeeded");
- if (r)
- return r;
+ if (adev->ip_blocks[i].version->funcs->hw_init) {
+ r = block->version->funcs->hw_init(&adev->ip_blocks[i]);
+ DRM_INFO("RE-INIT-early: %s %s\n", block->version->funcs->name,
+ r?"failed":"succeeded");
+ if (r)
+ return r;
+ }
block->status.hw = true;
}
}
@@ -3687,10 +3705,12 @@ static int amdgpu_device_ip_reinit_late_sriov(struct amdgpu_device *adev)
if (adev->ip_blocks[i].version->funcs->resume)
r = block->version->funcs->resume(&adev->ip_blocks[i]);
} else {
- r = block->version->funcs->hw_init(&adev->ip_blocks[i]);
+ if (adev->ip_blocks[i].version->funcs->hw_init)
+ r = block->version->funcs->hw_init(&adev->ip_blocks[i]);
}
- DRM_INFO("RE-INIT-late: %s %s\n", block->version->funcs->name, r?"failed":"succeeded");
+ DRM_INFO("RE-INIT-late: %s %s\n", block->version->funcs->name,
+ r ? "failed":"succeeded");
if (r)
return r;
block->status.hw = true;
--
2.34.1
prev parent reply other threads:[~2024-10-16 7:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-16 7:22 [PATCH v3 00/16] clean unused functions of amd_ip_funcs Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 01/16] drm/amdgpu: validate sw_init before function call Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 02/16] drm/amdgpu: clean the dummy sw_init functions Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 03/16] drm/amdgpu: validate sw_fini before function call Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 04/16] drm/amdgpu: clean the dummy sw_fini functions Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 05/16] drm/amdgpu: validate hw_fini before function call Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 06/16] drm/amdgpu: validate suspend " Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 07/16] drm/amdgpu: validate resume " Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 08/16] drm/amdgpu: validate wait_for_idle " Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 09/16] drm/amdgpu: clean the dummy resume functions Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 10/16] drm/amdgpu: clean the dummy suspend functions Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 11/16] drm/amdgpu: clean the dummy hw_fini functions Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 12/16] drm/amdgpu: clean the dummy wait_for_idle functions Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 13/16] drm/amdgpu: clean the dummy soft_reset functions Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 14/16] drm/amdgpu: clean unused functions of amd_ip_funcs Sunil Khatri
2024-10-16 7:22 ` [PATCH v3 15/16] drm/amdgpu: validate get_clockgating_state before use Sunil Khatri
2024-10-16 7:22 ` Sunil Khatri [this message]
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=20241016072258.1399698-17-sunil.khatri@amd.com \
--to=sunil.khatri@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@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