From: Soomin Kim Date: Mon, 2 Jan 2017 04:10:38 +0000 (+0900) Subject: [COMMON] thermal: of_thermal: Fix SVACE(WGID:82320) bug X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b83ecb29ce049abef6dcb0c1ea9e0a95bab3d262;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git [COMMON] thermal: of_thermal: Fix SVACE(WGID:82320) bug Uninitialized variable,'level', is used. Also, if there is parsing error, the value of level can be strange. So, fix both bug. Change-Id: I21a4eaf9cfed87f6ed14c4b2c35548a0dea4cdd7 Signed-off-by: Soomin Kim --- diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c index 0a87435d7d5c..b17dadba97e5 100644 --- a/drivers/thermal/of-thermal.c +++ b/drivers/thermal/of-thermal.c @@ -510,10 +510,12 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, struct __thermal_zone *__tz; void *thermal_block; struct ect_ap_thermal_function *function; - int i = 0, j = 0; + int i = 0, zone = 0; struct exynos_tmu_data *tmu_data; int hotplug_threshold_temp = 0, hotplug_flag = 0; - unsigned int level, freq; + unsigned int freq; + unsigned long level = THERMAL_CSTATE_INVALID; + unsigned long max_level = THERMAL_CSTATE_INVALID; int temperature; #endif @@ -571,35 +573,47 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, __tz->ntrips = __tz->num_tbps = function->num_of_range; dev_info(dev, "Trip count parsed from ECT : %d, zone : %s", function->num_of_range, tzd->type); + /* Find thermal zone number with thermal zone name defined in DT */ + for (zone = 0; zone < ARRAY_SIZE(tz_zone_names); zone++) + if (!strcasecmp(tzd->type, tz_zone_names[zone])) + break; + + if (zone == ARRAY_SIZE(tz_zone_names)) + dev_err(dev, "Error!!! Thermal zone name isn't matched!!\n"); + instance = list_first_entry(&tzd->thermal_instances, typeof(*instance), tz_node); - for (i = 0; i < function->num_of_range; ++i) { + for (i = 0; i < function->num_of_range && instance != NULL; ++i) { temperature = function->range_list[i].lower_bound_temperature; freq = function->range_list[i].max_frequency; - for (j = 0; j < ARRAY_SIZE(tz_zone_names); j++) - if (!strcasecmp(tzd->type, tz_zone_names[j])) { - switch (j) { - case MNGS_QUAD : - level = cpufreq_cooling_get_level(4, freq); - break; - case APOLLO : - level = cpufreq_cooling_get_level(0, freq); - break; - case GPU : - level = gpufreq_cooling_get_level(0, freq); - break; - case ISP : - level = isp_cooling_get_level(0, freq); - break; - case MNGS_DUAL : - level = cpufreq_cooling_get_level(4, freq); - break; - } - } + switch (zone) { + case MNGS_QUAD : + case MNGS_DUAL : + level = cpufreq_cooling_get_level(4, freq); + break; + case APOLLO : + level = cpufreq_cooling_get_level(0, freq); + break; + case GPU : + level = gpufreq_cooling_get_level(0, freq); + break; + case ISP : + level = isp_cooling_get_level(0, freq); + break; + default : + level = 0; + break; + } + + instance->cdev->ops->get_max_state(instance->cdev, &max_level); + + if ((zone == ARRAY_SIZE(tz_zone_names) && level == 0) || level == THERMAL_CSTATE_INVALID) + level = max_level; if (level > 100) { - dev_err(dev, "Level is strange!!! freq = %u, level = %u\n", freq, level); + dev_err(dev, "Level is invalid!!! freq = %u, level = %lu, max_level=%lu\n", + freq, level, max_level); level = 0; } @@ -610,7 +624,8 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, /* Change thermal instance information with tbps data */ instance->upper = __tz->tbps[i].max; instance = list_next_entry(instance, tz_node); - pr_info("Parsed From ECT : [%d] Temperature : %d, frequency : %u, level = %lu\n", i, temperature, freq, __tz->tbps[i].max); + pr_info("Parsed From ECT : [%d] Temperature : %d, frequency : %u, level = %lu\n", + i, temperature, freq, __tz->tbps[i].max); if (function->range_list[i].flag != hotplug_flag) { hotplug_threshold_temp = temperature;