drm/amdgpu: Fix cat debugfs amdgpu_regs_didt causes kernel null pointer
authorjsg <jsg@openbsd.org>
Mon, 22 Jan 2024 02:54:33 +0000 (02:54 +0000)
committerjsg <jsg@openbsd.org>
Mon, 22 Jan 2024 02:54:33 +0000 (02:54 +0000)
From Lu Yao
61dfdb779048332546358ac1847f0bbb07367162 in linux-6.6.y/6.6.13
2161e09cd05a50d80736fe397145340d2e8f6c05 in mainline linux

sys/dev/pci/drm/amd/amdgpu/amdgpu_debugfs.c

index 05405da..3f2126f 100644 (file)
@@ -638,6 +638,9 @@ 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)
+               return -EOPNOTSUPP;
+
        r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
        if (r < 0) {
                pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -694,6 +697,9 @@ 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)
+               return -EOPNOTSUPP;
+
        r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
        if (r < 0) {
                pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);