[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231122093509.34302-1-yaolu@kylinos.cn>
Date: Wed, 22 Nov 2023 17:35:09 +0800
From: Lu Yao <yaolu@...inos.cn>
To: airlied@...il.com, daniel@...ll.ch
Cc: alexander.deucher@....com, christian.koenig@....com,
amd-gfx@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org, Lu Yao <yaolu@...inos.cn>
Subject: [PATCH] drm/amdgpu: Fix cat debugfs amdgpu_regs_didt causes kernel null pointer
For 'AMDGPU_FAMILY_SI' family cards, in 'si_common_early_init' func, init
'didt_rreg' and 'didt_wreg' to 'NULL'. But in func
'amdgpu_debugfs_regs_didt_read/write', using 'RREG32_DIDT' 'WREG32_DIDT'
lacks of relevant judgment. And other 'amdgpu_ip_block_version' that use
these two definitions won't be added for 'AMDGPU_FAMILY_SI'.
So, add null pointer judgment before calling.
Signed-off-by: Lu Yao <yaolu@...inos.cn>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index a53f436fa9f1..797d7d3bfd50 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -638,6 +638,11 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,
if (size & 0x3 || *pos & 0x3)
return -EINVAL;
+ if (adev->didt_rreg == NULL) {
+ dev_err(adev->dev, "%s adev->didt_rreg is null!\n", __FUNC__);
+ return -EPERM;
+ }
+
r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
if (r < 0) {
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -694,6 +699,11 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user
if (size & 0x3 || *pos & 0x3)
return -EINVAL;
+ if (adev->didt_wreg == NULL) {
+ dev_err(adev->dev, "%s adev->didt_wreg is null!\n", __FUNC__);
+ return -EPERM;
+ }
+
r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
if (r < 0) {
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
--
2.25.1
Powered by blists - more mailing lists