lkml.org 
[lkml]   [2023]   [Nov]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] drm/amdgpu: Fix cat debugfs amdgpu_regs_didt causes kernel null pointer
From
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@kylinos.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);

\
 
 \ /
  Last update: 2023-11-22 12:27    [W:0.080 / U:0.588 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site