static void response_scenario(void *data, void *user_data)
{
- static int cur_priority = INT_MAX;
struct pass_resource *res = data;
struct pass_thermal *thermal = &res->thermal;
- char **resp = user_data;
+ struct device_notifier_thermal_data *thermal_data = user_data;
int priority = res->config_data.res_thermal_priority;
char *scenario = thermal->scenarios[thermal->curr_scenario_idx].name;
* Inform the thermal scenario name to
* DEVICE_NOTIFIER_THERMAL_GET_SCENARIO client.
*/
- if (priority < cur_priority || !*resp) {
- cur_priority = priority;
- *resp = scenario;
- } else if (priority == cur_priority) {
+ if (priority < thermal_data->priority || !thermal_data->scenario) {
+ thermal_data->priority = priority;
+ thermal_data->scenario = scenario;
+ } else if (priority == thermal_data->priority) {
+ char *cur = thermal_data->scenario;
int i;
for (i = 0; i < thermal->num_scenarios; i++) {
- if (!strncmp(thermal->scenarios[i].name, *resp, strlen(*resp))) {
- if (i < thermal->curr_scenario_idx)
- *resp = scenario;
+ if (!strncmp(thermal->scenarios[i].name, cur, strlen(cur))) {
+ if (i > thermal->curr_scenario_idx)
+ thermal_data->scenario = scenario;
break;
}
}
*/
static int thermal_init_done(void *data, void *user_data)
{
- char *scenario = NULL;
+ struct device_notifier_thermal_data initial_state = {
+ .scenario = NULL,
+ .priority = INT_MAX,
+ };
+ char *scenario;
+ int priority;
int ret, i;
if (g_thermal)
g_thermal->list[i].name);
}
- device_notify(DEVICE_NOTIFIER_THERMAL_GET_SCENARIO, &scenario);
+ device_notify(DEVICE_NOTIFIER_THERMAL_GET_SCENARIO, &initial_state);
+
+ scenario = initial_state.scenario;
+ priority = initial_state.priority;
if (!scenario) {
_E("failed to get current scenario for thermal\n");
}
g_thermal->cur_scenario_idx = i;
+ g_thermal->cur_priority = priority;
return 0;
}
* of current thermal data and if so, updates scenario, or else adds
* data into current resource list.
*/
- if (priority > g_thermal->cur_priority) {
+ if (priority < g_thermal->cur_priority) {
g_thermal->cur_priority = priority;
g_ptr_array_free(g_thermal->resources, TRUE);
g_thermal->resources = g_ptr_array_new_with_free_func(free);
scenario = thermal_data->scenario;
/* Ignore the notification of lower priority resources */
- if (thermal_data->priority < g_thermal->cur_priority)
+ if (thermal_data->priority > g_thermal->cur_priority)
return 0;
ret = thermal_handle_notifier_data(thermal_data);