pass: thermal: Fix to copy scenario name for thermal_data 89/263889/6 accepted/tizen/6.5/unified/20211028.115350 accepted/tizen/unified/20210926.235732 submit/tizen/20210924.100744 submit/tizen_6.5/20211028.162501 tizen_6.5.m2_release
authorDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 13 Sep 2021 05:18:15 +0000 (14:18 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 23 Sep 2021 12:17:36 +0000 (21:17 +0900)
Scenario name in thermal_data can be modified by thermal module, so
it has side-effect intruding supported scenario list. This fixes to
copy scenario instead of assigning pointer to prevent side-effect.

Change-Id: I21fde12fed6bcd72fb83a6171e1b0a6d350261bd
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
include/pass/common.h
include/pass/device-notifier.h
src/pass/pass-thermal.c
src/pass/pass.h
src/thermal/thermal.c

index 9cade8b61d558717604ee79a4d6ed3e8b2780f2b..d0f0100cc0c0e5d07fa542abbe16820e44bd62d3 100644 (file)
@@ -32,6 +32,7 @@
 typedef unsigned int uint32;
 typedef unsigned long long uint64;
 
+#define BUFF_MAX        255
 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
 
 /*
index e72907a29065360aed59ad5ff3c6b8f38f05cad2..4af325a358c84cc89ce8668f32f6ec90ab8e7f05 100644 (file)
@@ -21,6 +21,7 @@
 #define __DEVICE_NOTIFIER_H__
 
 #include <stdbool.h>
+#include <pass/common.h>
 
 enum device_notifier_type {
        DEVICE_NOTIFIER_INIT_DONE,
@@ -40,7 +41,7 @@ struct device_notifier {
 /* data structure for DEVICE_NOTIFIER_THERMAL */
 struct device_notifier_thermal_data {
        char *name;
-       char *scenario;
+       char scenario[BUFF_MAX];
        int priority;
 };
 
index fb3f159f0381d065ff23bb6ea0e938e6ef913888..efde403cac41b8b8cfd2eeac58d34531119b00a6 100644 (file)
@@ -159,10 +159,10 @@ static void notify_thermal_data(void *data, void *user_data)
        struct pass_resource *res = data;
        struct pass_thermal *thermal = &res->thermal;
        struct device_notifier_thermal_data thermal_data;
+       char *scenario = thermal->scenarios[thermal->curr_scenario_idx].name;
 
        thermal_data.name = res->config_data.res_thermal_name;
-       thermal_data.scenario =
-               thermal->scenarios[thermal->curr_scenario_idx].name;
+       memcpy(thermal_data.scenario, scenario, BUFF_MAX);
        thermal_data.priority = res->config_data.res_thermal_priority;
 
        /*
@@ -216,9 +216,9 @@ static void response_scenario(void *data, void *user_data)
         * Inform the thermal scenario name to
         * DEVICE_NOTIFIER_THERMAL_GET_SCENARIO client.
         */
-       if (priority < thermal_data->priority || !thermal_data->scenario) {
+       if (priority < thermal_data->priority || strlen(thermal_data->scenario) == 0) {
                thermal_data->priority = priority;
-               thermal_data->scenario = scenario;
+               memcpy(thermal_data->scenario, scenario, BUFF_MAX);
        } else if (priority == thermal_data->priority) {
                char *cur = thermal_data->scenario;
                int i;
@@ -226,7 +226,7 @@ static void response_scenario(void *data, void *user_data)
                for (i = 0; i < thermal->num_scenarios; i++) {
                        if (!strncmp(thermal->scenarios[i].name, cur, strlen(cur))) {
                                if (i > thermal->curr_scenario_idx)
-                                       thermal_data->scenario = scenario;
+                                       memcpy(thermal_data->scenario, scenario, BUFF_MAX);
                                break;
                        }
                }
index 0fb09d08c934cfb01bef8b59692eaecca96e798e..6afb875fe605c17e30857e23bfb4a1514d60113e 100644 (file)
@@ -39,7 +39,6 @@
 #include <pass/common.h>
 #include <pass/log.h>
 
-#define BUFF_MAX               255
 #define PASS_LEVEL_COND_MAX    3
 
 struct pass_resource;
index ae6c7f9cbab20b6b980d85d2bd9bd0e2ff14c70c..4788e33d8d5e0c7255f2a27268d1edfb429c290d 100644 (file)
@@ -107,7 +107,6 @@ static void thermal_free(void)
 static int thermal_init_done(void *data, void *user_data)
 {
        struct device_notifier_thermal_data initial_state = {
-               .scenario = NULL,
                .priority = INT_MAX,
        };
        char *scenario;
@@ -149,12 +148,14 @@ static int thermal_init_done(void *data, void *user_data)
                                        g_thermal->list[i].name);
        }
 
+       memset(&initial_state.scenario, 0, BUFF_MAX);
+
        device_notify(DEVICE_NOTIFIER_THERMAL_GET_SCENARIO, &initial_state);
 
        scenario = initial_state.scenario;
        priority = initial_state.priority;
 
-       if (!scenario) {
+       if (strlen(scenario) == 0) {
                _E("failed to get current scenario for thermal\n");
                g_ptr_array_free(g_thermal->resources, TRUE);
                free(g_thermal);