resource: system: Fix NULL_AFTER_DEREF issue 48/271748/4
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 28 Feb 2022 03:03:36 +0000 (12:03 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 28 Feb 2022 04:08:34 +0000 (13:08 +0900)
Change-Id: I9d25da863b004e11a71e0a44d7f8a0aebb22bc2c
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/resource/resource-system.c

index a96dd6b..64b0516 100644 (file)
@@ -81,12 +81,14 @@ static int system_get_avg_cpu_util(const struct resource *res,
                                const struct resource_attribute *attr,
                                void **data)
 {
-       struct system_resouce_data *sysdata = (struct system_resouce_data *)res->priv;
+       struct system_resouce_data *sysdata;
        double util;
 
-       if (!res || !attr || !data)
+       if (!res || !res->priv ||!attr || !data)
                return -EINVAL;
 
+       sysdata = (struct system_resouce_data *)res->priv;
+
        util = __calculate_cpu_util(attr->id, &sysdata->prev_avg, &sysdata->curr_avg);
        if (util < 0) {
                _W("failed to calculate average cpu util (%s.%d: %s)\n",
@@ -102,13 +104,16 @@ static int system_get_per_cpu_util(const struct resource *res,
                                const struct resource_attribute *attr,
                                void **data)
 {
-       struct system_resouce_data *sysdata = (struct system_resouce_data *)res->priv;
+       struct system_resouce_data *sysdata;
        struct array_value *array;
        double *utils;
        int i;
 
-       if (!res || !attr || !data)
+       if (!res || !res->priv ||!attr || !data)
                return -EINVAL;
+
+       sysdata = (struct system_resouce_data *)res->priv;
+
        array = calloc(1, sizeof(*array));
        if (!array)
                return -ENOMEM;