aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduardo Valentin <eduardo.valentin@ti.com>2013-04-05 08:32:28 -0400
committerZhang Rui <rui.zhang@intel.com>2013-04-14 21:34:28 -0400
commit63c4d919cf66b1b3ffa7861bddb50a697914af5b (patch)
tree374ed703373b2e25a4fd3f528a2a2b6f8a084cd6
parentd13cb03aef0c062dcdd16b411bd4c02c1574ff08 (diff)
thermal: introduce thermal_zone_get_zone_by_name helper function
This patch adds a helper function to get a reference of a thermal zone, based on the zone type name. It will perform a zone name lookup and return a reference to a thermal zone device that matches the name requested. In case the zone is not found or when several zones match same name or if the required parameters are invalid, it will return the corresponding error code (ERR_PTR). Cc: Durgadoss R <durgadoss.r@intel.com> Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com> Acked-by: Durgadoss R <durgadoss.r@intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
-rw-r--r--drivers/thermal/thermal_core.c38
-rw-r--r--include/linux/thermal.h1
2 files changed, 39 insertions, 0 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 4cdc3e327222..5045473485cf 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1754,6 +1754,44 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1754} 1754}
1755EXPORT_SYMBOL(thermal_zone_device_unregister); 1755EXPORT_SYMBOL(thermal_zone_device_unregister);
1756 1756
1757/**
1758 * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
1759 * @name: thermal zone name to fetch the temperature
1760 *
1761 * When only one zone is found with the passed name, returns a reference to it.
1762 *
1763 * Return: On success returns a reference to an unique thermal zone with
1764 * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
1765 * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
1766 */
1767struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
1768{
1769 struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
1770 unsigned int found = 0;
1771
1772 if (!name)
1773 goto exit;
1774
1775 mutex_lock(&thermal_list_lock);
1776 list_for_each_entry(pos, &thermal_tz_list, node)
1777 if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
1778 found++;
1779 ref = pos;
1780 }
1781 mutex_unlock(&thermal_list_lock);
1782
1783 /* nothing has been found, thus an error code for it */
1784 if (found == 0)
1785 ref = ERR_PTR(-ENODEV);
1786 else if (found > 1)
1787 /* Success only when an unique zone is found */
1788 ref = ERR_PTR(-EEXIST);
1789
1790exit:
1791 return ref;
1792}
1793EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
1794
1757#ifdef CONFIG_NET 1795#ifdef CONFIG_NET
1758static struct genl_family thermal_event_genl_family = { 1796static struct genl_family thermal_event_genl_family = {
1759 .id = GENL_ID_GENERATE, 1797 .id = GENL_ID_GENERATE,
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 3bda306f7a50..9af2f3a99658 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -239,6 +239,7 @@ void thermal_zone_device_update(struct thermal_zone_device *);
239struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, 239struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
240 const struct thermal_cooling_device_ops *); 240 const struct thermal_cooling_device_ops *);
241void thermal_cooling_device_unregister(struct thermal_cooling_device *); 241void thermal_cooling_device_unregister(struct thermal_cooling_device *);
242struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
242 243
243int get_tz_trend(struct thermal_zone_device *, int); 244int get_tz_trend(struct thermal_zone_device *, int);
244struct thermal_instance *get_thermal_instance(struct thermal_zone_device *, 245struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,