[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8e0d44ee-e3f3-43f7-9f83-6a4349fc1dc7@amd.com>
Date: Wed, 22 Nov 2023 12:26:35 +0100
From: Christian König <christian.koenig@....com>
To: Lu Yao <yaolu@...inos.cn>, airlied@...il.com, daniel@...ll.ch
Cc: alexander.deucher@....com, amd-gfx@...ts.freedesktop.org,
dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] drm/amdgpu: Fix cat debugfs amdgpu_regs_didt causes
kernel null pointer
Am 22.11.23 um 10:35 schrieb Lu Yao:
> 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__);
Please drop the dev_err(), this is not a device error but rather
userspace using a functionality not applicable for this device type.
> + return -EPERM;
Maybe rather use EOPNOTSUPP here.
Regards,
Christian.
> + }
> +
> 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);
Powered by blists - more mailing lists