drm/amdkfd: potential error pointer dereference in ioctl
authorDan Carpenter <dan.carpenter@linaro.org>
Tue, 6 Jun 2023 23:29:51 +0000 (19:29 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 9 Jun 2023 16:43:00 +0000 (12:43 -0400)
The "target" either comes from kfd_create_process() which returns error
pointers on error or kfd_lookup_process_by_pid() which returns NULL on
error.  So we need to check for both types of errors.

Fixes: 0ab2d7532b05 ("drm/amdkfd: prepare per-process debug enable and disable")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Jonathan Kim <jonathan.kim@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

index cce2abe..d655c5b 100644 (file)
@@ -2920,9 +2920,9 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v
                target = kfd_lookup_process_by_pid(pid);
        }
 
-       if (!target) {
+       if (IS_ERR_OR_NULL(target)) {
                pr_debug("Cannot find process PID %i to debug\n", args->pid);
-               r = -ESRCH;
+               r = target ? PTR_ERR(target) : -ESRCH;
                goto out;
        }