Thermal: pid_thermal_gov: Fix wrong comparison when temp is negative
Jinyoung Park [Wed, 27 Feb 2013 06:05:03 +0000 (15:05 +0900)]
Corrected variable type of trip_temp from unsigned long to signed long,
to prevent a wrong comparison issue when the temperature is below zero.
And changed order of temp and trip_temp comparison to reduce unnecessary
target calculation.

Bug 1233407

Change-Id: I95cdd67c08239c45115c66d9cfc93c68b59fd529
Signed-off-by: Jinyoung Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/204935
(cherry picked from commit 8e1d798187c653c0802e9462fc3ed8d6d59b4c77)
Reviewed-on: http://git-master/r/206847
Tested-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

drivers/thermal/pid_thermal_gov.c

index 9d04f73..c3bd2f6 100644 (file)
@@ -376,7 +376,8 @@ static int pid_thermal_gov_throttle(struct thermal_zone_device *tz, int trip)
 {
        struct thermal_instance *instance;
        enum thermal_trip_type trip_type;
-       unsigned long trip_temp, target;
+       long trip_temp;
+       unsigned long target;
 
        tz->ops->get_trip_type(tz, trip, &trip_type);
        tz->ops->get_trip_temp(tz, trip, &trip_temp);
@@ -384,7 +385,9 @@ static int pid_thermal_gov_throttle(struct thermal_zone_device *tz, int trip)
        mutex_lock(&tz->lock);
 
        list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
-               if (instance->trip != trip)
+               if ((instance->trip != trip) ||
+                               ((tz->temperature < trip_temp) &&
+                                (instance->target == THERMAL_NO_TARGET)))
                        continue;
 
                target = pid_thermal_gov_get_target(tz, instance->cdev,
@@ -394,12 +397,10 @@ static int pid_thermal_gov_throttle(struct thermal_zone_device *tz, int trip)
                else if (target < instance->lower)
                        target = instance->lower;
 
-               if (tz->temperature < trip_temp) {
-                       if ((target == instance->lower) &&
-                                       (instance->target == instance->lower ||
-                                       instance->target == THERMAL_NO_TARGET))
-                               target = THERMAL_NO_TARGET;
-               }
+               if ((tz->temperature < trip_temp) &&
+                               (instance->target == instance->lower) &&
+                               (target == instance->lower))
+                       target = THERMAL_NO_TARGET;
 
                if (instance->target == target)
                        continue;