]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/ras: Add NULL checks for ras_core sys_fn callbacks
authorSrinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Thu, 19 Mar 2026 05:40:10 +0000 (11:10 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 23 Mar 2026 18:06:07 +0000 (14:06 -0400)
Some ras core helper functions access ras_core and its callback
table (sys_fn) without validating them first.

Cc: Tao Zhou <tao.zhou1@amd.com>
Cc: YiPeng Chai <YiPeng.Chai@amd.com>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: YiPeng Chai <YiPeng.Chai@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/ras/rascore/ras_core.c

index e889baec378b060f94224fc5a3736c7b638a9c14..d6229f5f9a318d47a2cfe268185e9e8a6c55a779 100644 (file)
@@ -116,6 +116,9 @@ bool ras_core_gpu_in_reset(struct ras_core_context *ras_core)
 {
        uint32_t status = 0;
 
+       if (!ras_core)
+               return false;
+
        if (ras_core->sys_fn &&
                ras_core->sys_fn->check_gpu_status)
                ras_core->sys_fn->check_gpu_status(ras_core, &status);
@@ -127,6 +130,9 @@ bool ras_core_gpu_is_vf(struct ras_core_context *ras_core)
 {
        uint32_t status = 0;
 
+       if (!ras_core)
+               return false;
+
        if (ras_core->sys_fn &&
                ras_core->sys_fn->check_gpu_status)
                ras_core->sys_fn->check_gpu_status(ras_core, &status);
@@ -479,6 +485,9 @@ int ras_core_handle_fatal_error(struct ras_core_context *ras_core)
 
 uint32_t ras_core_get_curr_nps_mode(struct ras_core_context *ras_core)
 {
+       if (!ras_core)
+               return 0;
+
        if (ras_core->ras_nbio.ip_func &&
            ras_core->ras_nbio.ip_func->get_memory_partition_mode)
                return ras_core->ras_nbio.ip_func->get_memory_partition_mode(ras_core);
@@ -562,6 +571,8 @@ bool ras_core_ras_interrupt_detected(struct ras_core_context *ras_core)
 int ras_core_get_gpu_mem(struct ras_core_context *ras_core,
        enum gpu_mem_type mem_type, struct gpu_mem_block *gpu_mem)
 {
+       if (!ras_core || !gpu_mem)
+               return -EINVAL;
        if (ras_core->sys_fn && ras_core->sys_fn->get_gpu_mem)
                return ras_core->sys_fn->get_gpu_mem(ras_core, mem_type, gpu_mem);
 
@@ -572,6 +583,8 @@ int ras_core_get_gpu_mem(struct ras_core_context *ras_core,
 int ras_core_put_gpu_mem(struct ras_core_context *ras_core,
        enum gpu_mem_type mem_type, struct gpu_mem_block *gpu_mem)
 {
+       if (!ras_core || !gpu_mem)
+               return -EINVAL;
        if (ras_core->sys_fn && ras_core->sys_fn->put_gpu_mem)
                return ras_core->sys_fn->put_gpu_mem(ras_core, mem_type, gpu_mem);