Add NULL checks for helper input/output pointers that are directly
dereferenced, such as tm, seqno, dev_info and init_config.

Cc: Tao Zhou <[email protected]>
Cc: YiPeng Chai <[email protected]>
Cc: Dan Carpenter <[email protected]>
Cc: Christian König <[email protected]>
Cc: Alex Deucher <[email protected]>
Signed-off-by: Srinivasan Shanmugam <[email protected]>
Change-Id: I71bb9aa19f96c108e9ab1f4b7b72fe341e4d14aa
---
 drivers/gpu/drm/amd/ras/rascore/ras_core.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/amd/ras/rascore/ras_core.c 
b/drivers/gpu/drm/amd/ras/rascore/ras_core.c
index 5d5d2d6430d1..4e84220ef152 100644
--- a/drivers/gpu/drm/amd/ras/rascore/ras_core.c
+++ b/drivers/gpu/drm/amd/ras/rascore/ras_core.c
@@ -69,6 +69,9 @@ int ras_core_convert_timestamp_to_time(struct 
ras_core_context *ras_core,
        int seconds_per_minute = 60;
        int days, remaining_seconds;
 
+       if (!tm)
+               return -EINVAL;
+
        days = div64_u64_rem(timestamp, seconds_per_day, &remainder);
        /* remainder will always be less than seconds_per_day. */
        remaining_seconds = remainder;
@@ -271,6 +274,9 @@ struct ras_core_context *ras_core_create(struct 
ras_core_config *init_config)
        struct ras_core_context *ras_core;
        struct ras_core_config *config;
 
+       if (!init_config)
+               return NULL;
+
        ras_core = kzalloc(sizeof(*ras_core), GFP_KERNEL);
        if (!ras_core)
                return NULL;
@@ -625,6 +631,9 @@ int ras_core_event_notify(struct ras_core_context *ras_core,
 int ras_core_get_device_system_info(struct ras_core_context *ras_core,
                struct device_system_info *dev_info)
 {
+       if (!dev_info)
+               return -EINVAL;
+
        if (ras_core && ras_core->sys_fn &&
                ras_core->sys_fn->get_device_system_info)
                return ras_core->sys_fn->get_device_system_info(ras_core, 
dev_info);
-- 
2.34.1

Reply via email to