amdkfd: Check kvmalloc return before memcpy
authorKent Russell <kent.russell@amd.com>
Mon, 2 Nov 2020 16:17:59 +0000 (11:17 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 4 Nov 2020 02:00:40 +0000 (21:00 -0500)
If we can't kvmalloc the pcrat_image, then we shouldn't memcpy

Signed-off-by: Kent Russell <kent.russell@amd.com>
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_crat.c

index 5e2254b9e93165bb03af515256ebf1e3a67aead6..3de5e14c5ae316f559518e13bbf73ef2922da386 100644 (file)
@@ -798,10 +798,10 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
        }
 
        pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL);
-       memcpy(pcrat_image, crat_table, crat_table->length);
        if (!pcrat_image)
                return -ENOMEM;
 
+       memcpy(pcrat_image, crat_table, crat_table->length);
        *crat_image = pcrat_image;
        *size = crat_table->length;