Staging: r8192E_core.c: use %pM to shown MAC address
[safe/jmp/linux-2.6] / drivers / thermal / thermal_sys.c
index d0b093b..5066de5 100644 (file)
@@ -180,15 +180,15 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
 
        switch (type) {
        case THERMAL_TRIP_CRITICAL:
-               return sprintf(buf, "critical");
+               return sprintf(buf, "critical\n");
        case THERMAL_TRIP_HOT:
-               return sprintf(buf, "hot");
+               return sprintf(buf, "hot\n");
        case THERMAL_TRIP_PASSIVE:
-               return sprintf(buf, "passive");
+               return sprintf(buf, "passive\n");
        case THERMAL_TRIP_ACTIVE:
-               return sprintf(buf, "active");
+               return sprintf(buf, "active\n");
        default:
-               return sprintf(buf, "unknown");
+               return sprintf(buf, "unknown\n");
        }
 }
 
@@ -225,6 +225,12 @@ passive_store(struct device *dev, struct device_attribute *attr,
        if (!sscanf(buf, "%d\n", &state))
                return -EINVAL;
 
+       /* sanity check: values below 1000 millicelcius don't make sense
+        * and can cause the system to go into a thermal heart attack
+        */
+       if (state && state < 1000)
+               return -EINVAL;
+
        if (state && !tz->forced_passive) {
                mutex_lock(&thermal_list_lock);
                list_for_each_entry(cdev, &thermal_cdev_list, node) {
@@ -235,6 +241,8 @@ passive_store(struct device *dev, struct device_attribute *attr,
                                                                 cdev);
                }
                mutex_unlock(&thermal_list_lock);
+               if (!tz->passive_delay)
+                       tz->passive_delay = 1000;
        } else if (!state && tz->forced_passive) {
                mutex_lock(&thermal_list_lock);
                list_for_each_entry(cdev, &thermal_cdev_list, node) {
@@ -245,17 +253,12 @@ passive_store(struct device *dev, struct device_attribute *attr,
                                                                   cdev);
                }
                mutex_unlock(&thermal_list_lock);
+               tz->passive_delay = 0;
        }
 
        tz->tc1 = 1;
        tz->tc2 = 1;
 
-       if (!tz->passive_delay)
-               tz->passive_delay = 1000;
-
-       if (!tz->polling_delay)
-               tz->polling_delay = 10000;
-
        tz->forced_passive = state;
 
        thermal_zone_device_update(tz);
@@ -374,7 +377,7 @@ thermal_cooling_device_cur_state_store(struct device *dev,
        if (!sscanf(buf, "%ld\n", &state))
                return -EINVAL;
 
-       if (state < 0)
+       if ((long)state < 0)
                return -EINVAL;
 
        result = cdev->ops->set_cur_state(cdev, state);
@@ -417,7 +420,7 @@ static LIST_HEAD(thermal_hwmon_list);
 static ssize_t
 name_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct thermal_hwmon_device *hwmon = dev->driver_data;
+       struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
        return sprintf(buf, "%s\n", hwmon->type);
 }
 static DEVICE_ATTR(name, 0444, name_show, NULL);
@@ -488,7 +491,7 @@ thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
                result = PTR_ERR(hwmon->device);
                goto free_mem;
        }
-       hwmon->device->driver_data = hwmon;
+       dev_set_drvdata(hwmon->device, hwmon);
        result = device_create_file(hwmon->device, &dev_attr_name);
        if (result)
                goto unregister_hwmon_device;
@@ -953,7 +956,12 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
        mutex_lock(&tz->lock);
 
-       tz->ops->get_temp(tz, &temp);
+       if (tz->ops->get_temp(tz, &temp)) {
+               /* get_temp failed - retry it later */
+               printk(KERN_WARNING PREFIX "failed to read out thermal zone "
+                      "%d\n", tz->id);
+               goto leave;
+       }
 
        for (count = 0; count < tz->trips; count++) {
                tz->ops->get_trip_type(tz, count, &trip_type);
@@ -961,7 +969,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
                switch (trip_type) {
                case THERMAL_TRIP_CRITICAL:
-                       if (temp > trip_temp) {
+                       if (temp >= trip_temp) {
                                if (tz->ops->notify)
                                        ret = tz->ops->notify(tz, count,
                                                              trip_type);
@@ -974,7 +982,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
                        }
                        break;
                case THERMAL_TRIP_HOT:
-                       if (temp > trip_temp)
+                       if (temp >= trip_temp)
                                if (tz->ops->notify)
                                        tz->ops->notify(tz, count, trip_type);
                        break;
@@ -986,14 +994,14 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
                                cdev = instance->cdev;
 
-                               if (temp > trip_temp)
+                               if (temp >= trip_temp)
                                        cdev->ops->set_cur_state(cdev, 1);
                                else
                                        cdev->ops->set_cur_state(cdev, 0);
                        }
                        break;
                case THERMAL_TRIP_PASSIVE:
-                       if (temp > trip_temp || tz->passive)
+                       if (temp >= trip_temp || tz->passive)
                                thermal_zone_device_passive(tz, temp,
                                                            trip_temp, count);
                        break;
@@ -1005,10 +1013,14 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
                                            THERMAL_TRIPS_NONE);
 
        tz->last_temperature = temp;
+
+      leave:
        if (tz->passive)
                thermal_zone_device_set_polling(tz, tz->passive_delay);
        else if (tz->polling_delay)
                thermal_zone_device_set_polling(tz, tz->polling_delay);
+       else
+               thermal_zone_device_set_polling(tz, 0);
        mutex_unlock(&tz->lock);
 }
 EXPORT_SYMBOL(thermal_zone_device_update);