Merge tag 'rdma-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[cascardo/linux.git] / drivers / thermal / thermal_sys.c
index 220ce7e..022bacb 100644 (file)
@@ -23,6 +23,8 @@
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/err.h>
@@ -39,8 +41,6 @@ MODULE_AUTHOR("Zhang Rui");
 MODULE_DESCRIPTION("Generic thermal management sysfs support");
 MODULE_LICENSE("GPL");
 
-#define PREFIX "Thermal: "
-
 struct thermal_cooling_device_instance {
        int id;
        char name[THERMAL_NAME_LENGTH];
@@ -60,13 +60,11 @@ static LIST_HEAD(thermal_tz_list);
 static LIST_HEAD(thermal_cdev_list);
 static DEFINE_MUTEX(thermal_list_lock);
 
-static unsigned int thermal_event_seqnum;
-
 static int get_idr(struct idr *idr, struct mutex *lock, int *id)
 {
        int err;
 
-      again:
+again:
        if (unlikely(idr_pre_get(idr, GFP_KERNEL) == 0))
                return -ENOMEM;
 
@@ -152,9 +150,9 @@ mode_store(struct device *dev, struct device_attribute *attr,
        if (!tz->ops->set_mode)
                return -EPERM;
 
-       if (!strncmp(buf, "enabled", sizeof("enabled")))
+       if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
                result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
-       else if (!strncmp(buf, "disabled", sizeof("disabled")))
+       else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
                result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
        else
                result = -EINVAL;
@@ -283,8 +281,7 @@ passive_show(struct device *dev, struct device_attribute *attr,
 static DEVICE_ATTR(type, 0444, type_show, NULL);
 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
 static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
-static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, \
-                  passive_store);
+static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
 
 static struct device_attribute trip_point_attrs[] = {
        __ATTR(trip_point_0_type, 0444, trip_point_type_show, NULL),
@@ -313,22 +310,6 @@ static struct device_attribute trip_point_attrs[] = {
        __ATTR(trip_point_11_temp, 0444, trip_point_temp_show, NULL),
 };
 
-#define TRIP_POINT_ATTR_ADD(_dev, _index, result)     \
-do {    \
-       result = device_create_file(_dev,       \
-                               &trip_point_attrs[_index * 2]); \
-       if (result)     \
-               break;  \
-       result = device_create_file(_dev,       \
-                       &trip_point_attrs[_index * 2 + 1]);     \
-} while (0)
-
-#define TRIP_POINT_ATTR_REMOVE(_dev, _index)   \
-do {   \
-       device_remove_file(_dev, &trip_point_attrs[_index * 2]);        \
-       device_remove_file(_dev, &trip_point_attrs[_index * 2 + 1]);    \
-} while (0)
-
 /* sys I/F for cooling device */
 #define to_cooling_device(_dev)        \
        container_of(_dev, struct thermal_cooling_device, device)
@@ -835,15 +816,14 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
                return 0;
 
        device_remove_file(&tz->device, &dev->attr);
-      remove_symbol_link:
+remove_symbol_link:
        sysfs_remove_link(&tz->device.kobj, dev->name);
-      release_idr:
+release_idr:
        release_idr(&tz->idr, &tz->lock, dev->id);
-      free_mem:
+free_mem:
        kfree(dev);
        return result;
 }
-
 EXPORT_SYMBOL(thermal_zone_bind_cooling_device);
 
 /**
@@ -873,14 +853,13 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
 
        return -ENODEV;
 
-      unbind:
+unbind:
        device_remove_file(&tz->device, &pos->attr);
        sysfs_remove_link(&tz->device.kobj, pos->name);
        release_idr(&tz->idr, &tz->lock, pos->id);
        kfree(pos);
        return 0;
 }
-
 EXPORT_SYMBOL(thermal_zone_unbind_cooling_device);
 
 static void thermal_release(struct device *dev)
@@ -888,7 +867,8 @@ static void thermal_release(struct device *dev)
        struct thermal_zone_device *tz;
        struct thermal_cooling_device *cdev;
 
-       if (!strncmp(dev_name(dev), "thermal_zone", sizeof "thermal_zone" - 1)) {
+       if (!strncmp(dev_name(dev), "thermal_zone",
+                    sizeof("thermal_zone") - 1)) {
                tz = to_thermal_zone(dev);
                kfree(tz);
        } else {
@@ -908,8 +888,9 @@ static struct class thermal_class = {
  * @devdata:   device private data.
  * @ops:               standard thermal cooling devices callbacks.
  */
-struct thermal_cooling_device *thermal_cooling_device_register(
-     char *type, void *devdata, const struct thermal_cooling_device_ops *ops)
+struct thermal_cooling_device *
+thermal_cooling_device_register(char *type, void *devdata,
+                               const struct thermal_cooling_device_ops *ops)
 {
        struct thermal_cooling_device *cdev;
        struct thermal_zone_device *pos;
@@ -974,12 +955,11 @@ struct thermal_cooling_device *thermal_cooling_device_register(
        if (!result)
                return cdev;
 
-      unregister:
+unregister:
        release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
        device_unregister(&cdev->device);
        return ERR_PTR(result);
 }
-
 EXPORT_SYMBOL(thermal_cooling_device_register);
 
 /**
@@ -1024,7 +1004,6 @@ void thermal_cooling_device_unregister(struct
        device_unregister(&cdev->device);
        return;
 }
-
 EXPORT_SYMBOL(thermal_cooling_device_unregister);
 
 /**
@@ -1044,8 +1023,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
        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);
+               pr_warn("failed to read out thermal zone %d\n", tz->id);
                goto leave;
        }
 
@@ -1060,9 +1038,8 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
                                        ret = tz->ops->notify(tz, count,
                                                              trip_type);
                                if (!ret) {
-                                       printk(KERN_EMERG
-                                              "Critical temperature reached (%ld C), shutting down.\n",
-                                              temp/1000);
+                                       pr_emerg("Critical temperature reached (%ld C), shutting down\n",
+                                                temp/1000);
                                        orderly_poweroff(true);
                                }
                        }
@@ -1100,7 +1077,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
        tz->last_temperature = temp;
 
-      leave:
+leave:
        if (tz->passive)
                thermal_zone_device_set_polling(tz, tz->passive_delay);
        else if (tz->polling_delay)
@@ -1199,7 +1176,12 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
        }
 
        for (count = 0; count < trips; count++) {
-               TRIP_POINT_ATTR_ADD(&tz->device, count, result);
+               result = device_create_file(&tz->device,
+                                           &trip_point_attrs[count * 2]);
+               if (result)
+                       break;
+               result = device_create_file(&tz->device,
+                                           &trip_point_attrs[count * 2 + 1]);
                if (result)
                        goto unregister;
                tz->ops->get_trip_type(tz, count, &trip_type);
@@ -1235,12 +1217,11 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
        if (!result)
                return tz;
 
-      unregister:
+unregister:
        release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
        device_unregister(&tz->device);
        return ERR_PTR(result);
 }
-
 EXPORT_SYMBOL(thermal_zone_device_register);
 
 /**
@@ -1279,9 +1260,12 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
        if (tz->ops->get_mode)
                device_remove_file(&tz->device, &dev_attr_mode);
 
-       for (count = 0; count < tz->trips; count++)
-               TRIP_POINT_ATTR_REMOVE(&tz->device, count);
-
+       for (count = 0; count < tz->trips; count++) {
+               device_remove_file(&tz->device,
+                                  &trip_point_attrs[count * 2]);
+               device_remove_file(&tz->device,
+                                  &trip_point_attrs[count * 2 + 1]);
+       }
        thermal_remove_hwmon_sysfs(tz);
        release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
        idr_destroy(&tz->idr);
@@ -1289,7 +1273,6 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
        device_unregister(&tz->device);
        return;
 }
-
 EXPORT_SYMBOL(thermal_zone_device_unregister);
 
 #ifdef CONFIG_NET
@@ -1312,10 +1295,11 @@ int thermal_generate_netlink_event(u32 orig, enum events event)
        void *msg_header;
        int size;
        int result;
+       static unsigned int thermal_event_seqnum;
 
        /* allocate memory */
-       size = nla_total_size(sizeof(struct thermal_genl_event)) + \
-                               nla_total_size(0);
+       size = nla_total_size(sizeof(struct thermal_genl_event)) +
+              nla_total_size(0);
 
        skb = genlmsg_new(size, GFP_ATOMIC);
        if (!skb)
@@ -1331,8 +1315,8 @@ int thermal_generate_netlink_event(u32 orig, enum events event)
        }
 
        /* fill the data */
-       attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT, \
-                       sizeof(struct thermal_genl_event));
+       attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT,
+                          sizeof(struct thermal_genl_event));
 
        if (!attr) {
                nlmsg_free(skb);
@@ -1359,7 +1343,7 @@ int thermal_generate_netlink_event(u32 orig, enum events event)
 
        result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC);
        if (result)
-               printk(KERN_INFO "failed to send netlink event:%d", result);
+               pr_info("failed to send netlink event:%d\n", result);
 
        return result;
 }