pass: hal: Check whether parameter is valid or not 03/138803/2
authorChanwoo Choi <cw00.choi@samsung.com>
Fri, 14 Jul 2017 01:08:21 +0000 (10:08 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 14 Jul 2017 01:13:48 +0000 (10:13 +0900)
This patch checks whether the parameter is valid or not
in order to prevent the unexpected behavior.

Change-Id: Idb0a3c97f15a95231f39569ac528ab4b1001eded
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pass/pass-hal.c

index a68739935b6f462ab19a4f5e1dd39e4d4b121400..dae77fc33a631025668e9f434baf28320f67b1fa 100644 (file)
@@ -114,7 +114,7 @@ int pass_set_curr_governor(struct pass_resource *res, char *governor)
        char *res_name;
        int res_type;
 
-       if (!res)
+       if (!res || !governor)
                return -EINVAL;
 
        res_name = res->cdata.res_name;
@@ -294,7 +294,7 @@ int pass_get_online_state(struct pass_resource *res, int cpu)
        char *res_name;
        int res_type;
 
-       if (!res)
+       if (!res || cpu < 0)
                return -EINVAL;
 
        res_name = res->cdata.res_name;
@@ -316,7 +316,7 @@ int pass_set_online_state(struct pass_resource *res, int cpu, int on)
        char *res_name;
        int res_type;
 
-       if (!res || on < 0)
+       if (!res || cpu < 0 || on < 0)
                return -EINVAL;
 
        res_name = res->cdata.res_name;
@@ -454,7 +454,7 @@ int pass_get_tmu_policy(struct pass_resource *res, char *policy)
        char *res_thermal_name;
        int res_type;
 
-       if (!res)
+       if (!res || !policy)
                return -EINVAL;
 
        /*
@@ -503,14 +503,20 @@ int pass_set_pmqos_data(struct pass_resource *res, void *data)
 
 int pass_get_resource(struct pass_resource *res)
 {
-       struct pass_conf_data *cdata = &res->cdata;
+       struct pass_conf_data *cdata;
        struct pass_resource_info *info;
-       char *res_name = cdata->res_name;
+       char *res_name;
        char name[BUFF_MAX];
-       int res_type = cdata->res_type;
+       int res_type;
        int ret;
        int len;
 
+       if (!res)
+               return -EINVAL;
+       cdata = &res->cdata;
+       res_name = cdata->res_name;
+       res_type = cdata->res_type;
+
        switch (res_type) {
        case PASS_RESOURCE_CPU_ID:
                len = strlen(PASS_RESOURCE_CPU_NAME);
@@ -579,13 +585,19 @@ int pass_get_resource(struct pass_resource *res)
 
 int pass_put_resource(struct pass_resource *res)
 {
-       struct pass_conf_data *cdata = &res->cdata;
+       struct pass_conf_data *cdata;
        struct pass_resource_common *common;
        struct pass_resource_info *info;
-       char *res_name = cdata->res_name;
-       int res_type = cdata->res_type;
+       char *res_name;
+       int res_type;
        int ret;
 
+       if (!res)
+               return -EINVAL;
+       cdata = &res->cdata;
+       res_name = cdata->res_name;
+       res_type = cdata->res_type;
+
        switch (res_type) {
        case PASS_RESOURCE_CPU_ID:
                common = (struct pass_resource_common*)res->hal.cpu;