diff mbox series

[v4,2/4] thermal: core: Get thermal zone by id

Message ID 20200706105538.2159-2-daniel.lezcano@linaro.org
State Accepted
Commit 329b064fbd13d6526fdc35d4a220adedeadf0816
Headers show
Series [v4,1/4] thermal: core: Add helpers to browse the cdev, tz and governor list | expand

Commit Message

Daniel Lezcano July 6, 2020, 10:55 a.m. UTC
The next patch will introduce the generic netlink protocol to handle
events, sampling and command from the thermal framework. In order to
deal with the thermal zone, it uses its unique identifier to
characterize it in the message. Passing an integer is more efficient
than passing an entire string.

This change provides a function returning back a thermal zone pointer
corresponding to the identifier passed as parameter.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>

---
 drivers/thermal/thermal_core.c | 14 ++++++++++++++
 drivers/thermal/thermal_core.h |  2 ++
 2 files changed, 16 insertions(+)

-- 
2.17.1

Comments

Zhang Rui July 7, 2020, 1:53 a.m. UTC | #1
On Mon, 2020-07-06 at 12:55 +0200, Daniel Lezcano wrote:
> The next patch will introduce the generic netlink protocol to handle

> events, sampling and command from the thermal framework. In order to

> deal with the thermal zone, it uses its unique identifier to

> characterize it in the message. Passing an integer is more efficient

> than passing an entire string.

> 

> This change provides a function returning back a thermal zone pointer

> corresponding to the identifier passed as parameter.

> 

> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>


Acked-by: Zhang Rui <rui.zhang@intel.com>

> ---

>  drivers/thermal/thermal_core.c | 14 ++++++++++++++

>  drivers/thermal/thermal_core.h |  2 ++

>  2 files changed, 16 insertions(+)

> 

> diff --git a/drivers/thermal/thermal_core.c

> b/drivers/thermal/thermal_core.c

> index 9caaa0b6d662..5fae1621fb01 100644

> --- a/drivers/thermal/thermal_core.c

> +++ b/drivers/thermal/thermal_core.c

> @@ -668,6 +668,20 @@ int for_each_thermal_zone(int (*cb)(struct

> thermal_zone_device *, void *),

>  	return ret;

>  }

>  

> +struct thermal_zone_device *thermal_zone_get_by_id(int id)

> +{

> +	struct thermal_zone_device *tz = NULL;

> +

> +	mutex_lock(&thermal_list_lock);

> +	list_for_each_entry(tz, &thermal_tz_list, node) {

> +		if (tz->id == id)

> +			break;

> +	}

> +	mutex_unlock(&thermal_list_lock);

> +

> +	return tz;

> +}

> +

>  void thermal_zone_device_unbind_exception(struct thermal_zone_device

> *tz,

>  					  const char *cdev_type, size_t

> size)

>  {

> diff --git a/drivers/thermal/thermal_core.h

> b/drivers/thermal/thermal_core.h

> index 71d88dac0791..4f8389efaa62 100644

> --- a/drivers/thermal/thermal_core.h

> +++ b/drivers/thermal/thermal_core.h

> @@ -50,6 +50,8 @@ int for_each_thermal_cooling_device(int

> (*cb)(struct thermal_cooling_device *,

>  int for_each_thermal_governor(int (*cb)(struct thermal_governor *,

> void *),

>  			      void *thermal_governor);

>  

> +struct thermal_zone_device *thermal_zone_get_by_id(int id);

> +

>  struct thermal_attr {

>  	struct device_attribute attr;

>  	char name[THERMAL_NAME_LENGTH];
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 9caaa0b6d662..5fae1621fb01 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -668,6 +668,20 @@  int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
 	return ret;
 }
 
+struct thermal_zone_device *thermal_zone_get_by_id(int id)
+{
+	struct thermal_zone_device *tz = NULL;
+
+	mutex_lock(&thermal_list_lock);
+	list_for_each_entry(tz, &thermal_tz_list, node) {
+		if (tz->id == id)
+			break;
+	}
+	mutex_unlock(&thermal_list_lock);
+
+	return tz;
+}
+
 void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
 					  const char *cdev_type, size_t size)
 {
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 71d88dac0791..4f8389efaa62 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -50,6 +50,8 @@  int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
 int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
 			      void *thermal_governor);
 
+struct thermal_zone_device *thermal_zone_get_by_id(int id);
+
 struct thermal_attr {
 	struct device_attribute attr;
 	char name[THERMAL_NAME_LENGTH];